吴密的博客

每天进步一点点
posts - 12, comments - 1, trackbacks - 0, articles - 1

2015年4月1日

在本章我们介绍在serviceMIx 中图和使用 ActiveMQ、features命令,入门的3篇文章来自
http://servicemix.apache.org/docs/5.0.x/quickstart/index.html,有兴趣的可以再去看看英文的。

ActiveMQ
    每个
Apache ServiceMix的实例是一个嵌入式activemq jms代理,这样可以很方便的在同一台机器上使用持久消息来通信,
但是它也支持集群和负载均衡。
   在这个实例中,我们依然像上个例子一样,在2个目录中移动文件,把记录日志的部分改为发送一条jms消息到消息队列,
然后再创建一个新的route来接受事件并记录日志:
?xml version="1.0" encoding="UTF-8"?>
<blueprint
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
      http://www.osgi.org/xmlns/blueprint/v1.0.0
      http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">

    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
      <route>
        <from uri="file:activemq/input"/>
        <to uri="file:activemq/output"/>

        <setBody>
          <simple>
            FileMovedEvent(file: ${file:name}, timestamp: ${date:now:hh:MM:ss.SSS})
          </simple>
        </setBody>
        <to uri="activemq://events" />
      </route>
    </camelContext>
</blueprint>

   保存这个文件,并且放到serviceMix的deploy目录,会看到复制到 activemq/input 目录中的文件被复制到 activemq/output 

   接受消息
   在第一个文件中,除了复制文件,你看不到任何的log记录。它发送了jms消息,但是没有接受者,我们可以创建一个route来接受消息:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
      http://www.osgi.org/xmlns/blueprint/v1.0.0
      http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
      <route>
        <from uri="activemq://events"/>
        <to uri="log:events"/>
      </route>
    </camelContext>
</blueprint>

  你可以通过log:display来查看日志消息。你可以通过osgi:start 和 osgi:stop来启动和关闭这个bundle.当你重启完第一个bundle后,你收到所有文件移动后发出
的消息事件。

    features命令

karaf@root> features:list | grep camel
[uninstalled] [5.4.0           ] examples-activiti-camel                 servicemix-examples-5.4.0
[uninstalled] [5.4.0           ] examples-akka-camel                     servicemix-examples-5.4.0


karaf@root> features:install webconsole

karaf@root> features:list | grep webconsole
[installed  ] [2.4.1           ] webconsole                              karaf-2
.4.1               Karaf WebConsole for administration and monitoring

    通过features:install webconsole可以安装  webconsole bundle,成功后你可以通过  http://localhost:8181/system/console  用户名密码:smx/smx来
登录
,可以通过浏览器来上传、启动,停止bundle。

posted @ 2015-04-10 15:37 xiaolang 阅读(5155) | 评论 (0)编辑 收藏

本章我们通过一个简单的实例来介绍如何使用camel。
这个实例中,我们会把文件从目录
camel/input 移动到camel/output.为了方便我们跟踪哪些文件被移动,我们会记录日志。

1、创建一个xml
 ServiceMix中定义一个新的 route,最简单的方式之一就是定义一个Blueprint XML file,就像下边一样:

<?xml version="1.0" encoding="UTF-8"?>
<blueprint
    xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="
      http://www.osgi.org/xmlns/blueprint/v1.0.0
      http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
    <camelContext xmlns="http://camel.apache.org/schema/blueprint">
      <route>
        <from uri="file:camel/input"/>
        <log message="Moving ${file:name} to the output directory"/>
        <to uri="file:camel/output"/>
      </route>
    </camelContext>
</blueprint>
                                           

2.部署
   我们只需要将第一步创建的xml复制到serviceMix下的 deploy 目录,就会被serviceMix 识别并部署。你会看到被放到目录camel/input下的文件被
移动到camel/output,如果你使用log:display命令,会看到文件移动的日志:

2015-04-09 17:10:19,515 | INFO  | le://camel/input | route1
      | ?                                   ? | 116 - org.apache.camel.camel-cor
e - 2.14.1 | Moving test.xml.bak to the output directory

3. 使用命令行管理  route
使用osgi:list,你会看到刚才我们部署的bundle
[ 221] [Active     ] [Created     ] [       ] [   80] test.xml (0.0.0)
你会看到我们刚才部署的bundle ID是221,我们可以通过这个bundle ID来启动或者关闭bundle

karaf@root> osgi:stop 221
karaf@root> osgi:start 221

posted @ 2015-04-09 17:19 xiaolang 阅读(4465) | 评论 (0)编辑 收藏

本章我们主要介绍下如何安装serviceMiX,使用命令来查看osgi bundles、日志。

1、下载
serviceMiX5.4.0
http://servicemix.apache.org/downloads.html
到下载页面选取:
tar,gz  for Linux/Unix/MacOS X
zip for windows

如果仅仅是运行
serviceMiX,你需要jre1.6.x 或者 jre1.7.x  serviceMiX5.4.0大概需要100M的空间
如果你要开发自己的一些集成应用和osgi bundles,你还需要安装  jdk1.6.x 或者 jdk1.7.x  apache maven3.0.4 或者更高的版本


2.解压,指定<SERVICEMIX_HOME>.
解压,在环境变量中配置 <SERVICEMIX_HOME>.例如:C:\apache-servicemix

3.启动serviceMiX(windows)

C:\Users\Administrator>cd c:\apache-servicemix\bin

c:\apache-servicemix\bin>servicemix
Please wait while Apache ServiceMix is starting...
 27% [===================>                                                    ]


4.启动成功

Please wait while Apache ServiceMix is starting...
100% [========================================================================]
 ____                  _          __  __ _
/ ___|  ___ _ ____   _(_) ___ ___|  \/  (_)_  __
\___ \ / _ \ '__\ \ / / |/ __/ _ \ |\/| | \ \/ /
 ___) |  __/ |   \ V /| | (_|  __/ |  | | |>  <
|____/ \___|_|    \_/ |_|\___\___|_|  |_|_/_/\_\
  Apache ServiceMix (5.4.0)
Hit '<tab>' for a list of available commands
and '[cmd] --help' for help on a specific command.
Hit '<ctrl-d>' or 'osgi:shutdown' to shutdown ServiceMix.

5. 
使用命令 osgi:list  osgi:list|grep camel 查看bundles 

karaf@root> osgi:list
START LEVEL 100 , List Threshold: 50
   ID   State         Blueprint      Spring    Level  Name
[  81] [Active     ] [            ] [       ] [   50] geronimo-annotation_1.0_spec (1.1.1)
[  82] [Active     ] [            ] [       ] [   50] geronimo-jms_1.1_spec (1.1.1)
[  83] [Active     ] [            ] [       ] [   50] geronimo-j2ee-management_1.1_spec (1.0.1)
[  84] [Active     ] [            ] [       ] [   50] JAXB2 Basics - Runtime (0.6.4)
[  85] [Active     ] [            ] [       ] [   50] Apache ServiceMix :: Bundles :: jaxb-impl (2.2.1.1_2)

karaf@root> osgi:list|grep camel
[ 116] [Active     ] [            ] [       ] [   50] camel-core (2.14.1)
[ 117] [Active     ] [Created     ] [       ] [   50] camel-karaf-commands (2.14.1)
[ 118] [Active     ] [            ] [       ] [   50] camel-jms (2.14.1)
[ 124] [Active     ] [            ] [       ] [   50] camel-spring (2.14.1)
[ 125] [Active     ] [Created     ] [       ] [   50] camel-blueprint (2.14.1)

6.
使用log:display查看日志,其他 log:display-exception

karaf@root> log:display
2015-04-09 16:09:07,433 | INFO  | 0 - timer://wumi | timerToLog  | ?                                   ? | 116 - org.apache.camel.camel-cor
e - 2.14.1 | The message contains Hi from Camel at 2015-04-09 16:09:07

posted @ 2015-04-09 16:25 xiaolang 阅读(6320) | 评论 (1)编辑 收藏

今天下午发现mysql客户端连接服务端缓慢,windows 环境下,到目录 MYSQL_HOME/my.ini 中加入:skip-name-resolve,然后保存并重启mysql服务

问题解决。

查阅mysql官方网站得知,这属于官方一个系统上的特殊设定,就把他当成mysql的一个bug算了,不管链接的的方式是经过 hosts 或是 IP 的模式,他都会对 DNS
做反查。mysqld 会尝试去反查 IP -> dns ,由于反查解析过慢,就会无法应付过量的查询。





posted @ 2015-04-01 17:24 xiaolang 阅读(313) | 评论 (0)编辑 收藏