activeMQ訊息佇列詳細配置

2021-08-27 08:29:08 字數 3031 閱讀 8086

spring整合activemq方法

1.匯入座標

org.apache.activemqgroupid>

activemq-allartifactid>

5.14.0version>

dependency>

org.springframeworkgroupid>

spring-jmsartifactid>

4.3.3.releaseversion>

dependency>

org.springframeworkgroupid>

spring-contextartifactid>

4.3.3.releaseversion>

dependency>

org.springframeworkgroupid>

spring-context-supportartifactid>

4.3.3.releaseversion>

dependency>

org.springframeworkgroupid>

spring-webartifactid>

4.3.3.releaseversion>

dependency>

org.springframeworkgroupid>

spring-testartifactid>

4.3.3.releaseversion>

dependency>

junitgroupid>

junitartifactid>

4.12version>

dependency>

2.web.xml中配置核心***

contextconfiglocationparam-name>

context-param>

org.springframework.web.context.contextloaderlistenerlistener-class>

listener>

id="connectionfactoryamq"

brokerurl="tcp://localhost:61616"

username="admin"

password="admin"/>

4.2spring 整合 activemq

id="connectionfactory"

class="org.springframework.jms.connection.cachingconnectionfactory">

name="targetconnectionfactory"

ref="connectionfactoryamq">

property>

name="sessioncachesize"

value="100" />

bean>

4.2.1activemq配置生產者

id="jmsqueuetemplate"

class="org.springframework.jms.core.jmstemplate">

ref="connectionfactory" />

《引入spring整合的工廠》

name="pubsubdomain"

value="false" />

bean>

id="jmstopictemplate"

class="org.springframework.jms.core.jmstemplate">

ref="connectionfactory" />

name="pubsubdomain"

value="true" />

bean>

4.2.2activemq配置消費者

destination-type="queue"

container-type="default"

connection-factory="connectionfactory"

acknowledge="auto">

destination="queue_name"

ref="activeconsumersqueue"/>

destination="queue_name"

ref="activeconsumersqueue1"/>

jms:listener-container>

注:destination屬性內容引數為具體監聽發布訊息名字

ref屬性為消費者實體類的類名首字母小寫,如果在實體類註解上配置了具體name,ref屬性就為具體的name屬性

destination-type="topic"

container-type="default"

connection-factory="connectionfactory"

acknowledge="auto">

destination="topic_name"

ref="activeconsumerstopic"/>

destination="topic_name"

ref="activeconsumerstopic2"/>

jms:listener-container>

5.生產者實體類配置

@service

public

class

activemqtopic

});}

}

6.消費者實體類配置

6.1消費者類實現messagelistener介面

public

class

activeconsumersqueue

implements

messagelistener catch (jm***ception e)

}}

ActiveMQ訊息佇列

這個東西沒接觸到的時候挺懵的,用過一次之後,哇哦 public class producter catch jm ception e public void sendmessage string disname,listlist else thread.sleep 1000 int num coun...

activeMQ訊息佇列

session.auto acknowledge。當客戶成功的從receive 方法返回的時候,或者從messagelistener.onmessage方法成功返回的時候,會話自動確認客戶收到的訊息。session.client acknowledge。客戶通過訊息的 acknowledge 方法確...

ActiveMQ實現訊息佇列

實現訊息佇列 123 4567 891011 1213 1415 1617 1819 2021 2223 2425 2627 2829 3031 32 service public class providerservice 123 4567 891011 1213 1415 1617 1819 2...