ActiveMQ integration with business systems

Source: Internet
Author: User

ActiveMQ is a Java-based open-source Message Server product. Therefore, we can integrate it into a business system implemented through Java. The following is a brief summary of the integration method.

First, let's take a look at some core classes in ActiveMQ:

650) this. width = 650; "src =" http://www.bkjia.com/uploads/allimg/131228/152ZW925-0.jpg "title =" Drawing 1.jpg "/>

Org. apache. activemq. Service is an interface in ActiveMQ and defines the start and stop methods. Org. apache. activemq. broker. BrokerService is the core class in ActiveMQ. It implements the self-Service interface and is used to provide the Message Service externally. Org. apache. activemq. broker. XBeanBrokerService is a subclass of BrokerService. XBeanBrokerService instances can be generated through the xbean xml configuration file. When ActiveMQ is started as a separate service, its configuration file activemq. xml is in xbean xml format, and an XBeanBrokerService instance is generated after it is started.


1. Integration through the VM protocol:

Multiple protocols such as TCP, VM, and STOMP can be used when the client connects to the ActiveMQ Message Server. The VM Protocol indicates that the client searches for the ActiveMQ message server instance from the current JVM, establish a connection with the server. If no connection is found, the ActiveMQ message server instance is automatically created. If both the client and server are in the same JVM, The ActiveMQ Message Server can be automatically created and integrated with the business system through the VM protocol.


2. directly create a BrokerService instance:

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. Use the factory method to create a BrokerService instance:

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. directly create a BrokerService instance through Spring Configuration

<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. Use Spring configuration to create a BrokerService instance using BrokerFactoryBean:

<bean id="broker“class="org.apache.activemq.xbean.BrokerFactoryBean">  <property name="config"value="classpath:activemq.xml"/>  <property name="start"value="true" /></bean>




This article is from the "Learning document" blog, please be sure to keep this source http://zephiruswt.blog.51cto.com/5193151/1295254

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.