ActiveMQ与业务系统的集成
2013-09-12 20:06
204 查看
ActiveMQ是一款基于Java的开源消息服务器产品,因此,我们可以将其集成到通过Java实现的业务系统中。下面将对集成方法做一个简单的总结。
首先,我们看一下ActiveMQ中的部分核心类:
org.apache.activemq.Service是ActiveMQ中的一个接口,定义了start和stop方法。org.apache.activemq.broker.BrokerService是ActiveMQ中的核心类,其实现自Service接口,用于对外提供消息服务。org.apache.activemq.broker.XBeanBrokerService是BrokerService的一个子类,XBeanBrokerService实例可以通过xbean xml配置文件生成。ActiveMQ作为单独服务启动时,其配置文件activemq.xml就是xbean xml格式的,启动后生成的就是一个XBeanBrokerService实例。
1.通过VM协议实现集成:
客户端连接ActiveMQ消息服务器时,可以使用多种协议(TCP、VM、STOMP等),其中VM协议是指客户端会从当前JVM中查找ActiveMQ消息服务器实例,若查找到,则与其建立连接,若查找不到,则自动创建ActiveMQ消息服务器实例。如果客户端和服务器端都在一个JVM中,则可以通过VM协议实现ActiveMQ消息服务器的自动创建、与业务系统的集成。
2.直接创建BrokerService实例:
3.使用工厂方法创建BrokerService实例:
4.通过Spring配置直接创建BrokerService实例
5.通过Spring配置使用BrokerFactoryBean创建BrokerService实例:
本文出自 “学习文档” 博客,请务必保留此出处http://zephiruswt.blog.51cto.com/5193151/1295254
首先,我们看一下ActiveMQ中的部分核心类:
org.apache.activemq.Service是ActiveMQ中的一个接口,定义了start和stop方法。org.apache.activemq.broker.BrokerService是ActiveMQ中的核心类,其实现自Service接口,用于对外提供消息服务。org.apache.activemq.broker.XBeanBrokerService是BrokerService的一个子类,XBeanBrokerService实例可以通过xbean xml配置文件生成。ActiveMQ作为单独服务启动时,其配置文件activemq.xml就是xbean xml格式的,启动后生成的就是一个XBeanBrokerService实例。
1.通过VM协议实现集成:
客户端连接ActiveMQ消息服务器时,可以使用多种协议(TCP、VM、STOMP等),其中VM协议是指客户端会从当前JVM中查找ActiveMQ消息服务器实例,若查找到,则与其建立连接,若查找不到,则自动创建ActiveMQ消息服务器实例。如果客户端和服务器端都在一个JVM中,则可以通过VM协议实现ActiveMQ消息服务器的自动创建、与业务系统的集成。
2.直接创建BrokerService实例:
public static void main(String[] args)throws Exception { BrokerService broker = new BrokerService(); broker.setBrokerName("myBroker"); broker.setDataDirectory("data/"); SimpleAuthenticationPlugin authentication = newSimpleAuthenticationPlugin(); List<AuthenticationUser> users = newArrayList<AuthenticationUser>(); users.add(new AuthenticationUser("admin","password", "admins,publishers,consumers")); users.add(new AuthenticationUser("publisher","password", "publishers,consumers")); users.add(new AuthenticationUser("consumer","password", "consumers")); users.add(new AuthenticationUser("guest","password", "guests")); authentication.setUsers(users); broker.setPlugins(new BrokerPlugin[]{authentication}); broker.addConnector("tcp://localhost:61616"); broker.start(); System.out.println(); System.out.println("Press any key to stop the broker"); System.out.println(); System.in.read(); }
3.使用工厂方法创建BrokerService实例:
public static void main(String[] args)throws Exception { System.setProperty("activemq.base",System.getProperty("user.dir")); String configUri ="xbean:activemq.xml" URI brokerUri = new URI(configUri); BrokerService broker = BrokerFactory.createBroker(brokerUri); broker.start(); System.out.println(); System.out.println("Press any key to stop the broker"); System.out.println(); System.in.read(); }
4.通过Spring配置直接创建BrokerService实例
<bean id="simpleAuthPlugin“class="org.apache.activemq.security.SimpleAuthenticationPlugin"> <property name="users"> <util:list> <ref bean="admins" /> <ref bean="publishers" /> <ref bean="consumers" /> <ref bean="guests" /> </util:list> </property> </bean> <bean id="broker"class="org.apache.activemq.broker.BrokerService" init-method="start"destroy-method="stop"> <property name="brokerName"value="myBroker" /> <property name="persistent"value="false" /> <propertyname="transportConnectorURIs"> <list><value>tcp://localhost:61616</value></list> </property> <property name="plugins"> <list><refbean="simpleAuthPlugin"/></list> </property> </bean>
5.通过Spring配置使用BrokerFactoryBean创建BrokerService实例:
<bean id="broker“class="org.apache.activemq.xbean.BrokerFactoryBean"> <property name="config" value="classpath:activemq.xml"/> <property name="start"value="true" /> </bean>
本文出自 “学习文档” 博客,请务必保留此出处http://zephiruswt.blog.51cto.com/5193151/1295254
相关文章推荐
- ActiveMQ与业务系统的集成
- 集成activiti-modeler 到 自己的业务系统(集成流程跟踪-完美支持IE)
- MOSS与业务系统的集成 之 自定义Membership实现Forms方式验证
- activiti 5.14 activitimodeler与业务系统集成(业务系统为spring,struts2,mybatis结构)
- 不同业务系统集成模式(摘录MSDN)
- 云业务系统集成服务
- 工业物联网或系统集成中应用消息队列(ActiveMQ,C#的demo)的场景全面分析
- 公司多业务系统集成sso登录调研
- springboot 系统学习5 集成 activemq
- MOSS 2010:Visual Studio 2010开发体验(21)——使用Business Connectivity Service(BCS)集成业务系统
- 讨论一下用友ERP软件系统的优缺点与集成业务软件系统的优势
- 天翎myApps:助力业务系统集成
- MOSS 2010:Visual Studio 2010开发体验(21)——使用Business Connectivity Service(BCS)集成业务系统
- Slickflow.NET 开源工作流引擎基础介绍(二) -- 引擎组件和业务系统的集成
- 通用权限管理系统多语言开发接口 ,多业务子系统集成实现过程
- 工业物联网或系统集成中应用消息队列(ActiveMQ,C#的demo)的场景全面分析
- jBPM与业务系统集成-通过定制Task Instance等方式实现
- 业务系统如何集成工作流系统
- C#.NET 大型企业信息化系统集成快速开发平台 4.2 版本 - 几十套业务系统集中统一授权管理实现经验分享
- 集成activiti-modeler 到 自己的业务系统