ActiveMQ组件使用方法

时间:2022-08-28 07:26:08

由于组件使用了spring,故需要相关的spring包及配置

首先,需要加载对应的jar包

ActiveMQ组件使用方法

然后,编写调用类

ActiveMQ组件使用方法ActiveMQ组件使用方法
 1 package com.demo.testSpring;
 2 
 3 import com.jfinal.core.Controller;
 4 import com.jfinal.plugin.spring.Inject;
 5 import com.supermap.sm3dad.messagequeue.CMessageReceiver;
 6 import com.supermap.sm3dad.messagequeue.CMessageSender;
 7 
 8 public class testSpringController extends Controller{
 9     
10     @Inject.BY_NAME
11     private CMessageSender messagesender;
12     
13     @Inject.BY_NAME
14     private CMessageReceiver messagereceiver;
15     
16     public void send(){
17 
18         messagesender.sendMessage("hello",getPara("info"));
19         renderNull();
20     }
21     
22     public void get(){
23 
24         renderText(messagereceiver.receiveMessage("hello"));
25     }
26 }
mq操作示例类
ActiveMQ组件使用方法ActiveMQ组件使用方法
 1 <?xml version="1.0" encoding="UTF-8"?>
 2 <beans xmlns="http://www.springframework.org/schema/beans"
 3         xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
 4         xmlns:aop="http://www.springframework.org/schema/aop"
 5         xmlns:tx="http://www.springframework.org/schema/tx"
 6         xsi:schemaLocation="
 7             http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
 8             http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
 9             http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd">
10         
11     <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
12         <property name="brokerURL">
13             <value>tcp://localhost:61616?wireFormat.maxInactivityDuration=0</value>
14         </property>
15     </bean>
16     <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
17         <property name="connectionFactory">
18             <ref bean="connectionFactory"/>
19         </property>
20     </bean>
21     <bean id="messagesender" class="com.supermap.sm3dad.messagequeue.CMessageSender">
22         <property name="jmsTemplate" ref="jmsTemplate"/>
23         <!-- <property name="destination" ref="destination"/> -->
24     </bean>
25     <bean id="messagereceiver" class="com.supermap.sm3dad.messagequeue.CMessageReceiver">
26         <property name="jmsTemplate" ref="jmsTemplate"/>
27         <!-- <property name="destination" ref="destination"/> -->
28     </bean>
29     
30 </beans>
31     
spring配置