In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-16 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
Spring integrates what is the configuration of MQ. For this question, this article introduces the corresponding analysis and solution in detail, hoping to help more partners who want to solve this problem to find a more simple and feasible way.
Import org.apache.activemq.command.ActiveMQQueue;import org.apache.activemq.command.ActiveMQTopic;import org.apache.activemq.pool.PooledConnectionFactory;import org.springframework.beans.factory.annotation.Autowired;import org.springframework.context.annotation.Bean;import org.springframework.context.annotation.Configuration;import org.springframework.jms.core.JmsTemplate;import org.springframework.jms.listener.*;import org.springframework.jms.support.converter.SimpleMessageConverter;import org.springframework.scheduling.annotation.EnableAsync;import org.springframework.scheduling.annotation.EnableScheduling;import javax.jms.* @ Configuration@EnableAsync@EnableSchedulingpublic class MQConfig {/ * configure queue message template * @ param jmsFactory * @ return * / @ Bean public JmsTemplate queueTemplate (@ Autowired ConnectionFactory jmsFactory, @ Autowired ActiveMQQueue activeMQQueue) {var template = new JmsTemplate (jmsFactory); template.setDefaultDestination (activeMQQueue); template.setMessageConverter (new SimpleMessageConverter ()); return template } / * configure topic message template * @ param jmsFactory * @ param activeMQTopic * @ return * / @ Bean public JmsTemplate topicTemplate (@ Autowired ConnectionFactory jmsFactory, @ Autowired ActiveMQTopic activeMQTopic) {var template = new JmsTemplate (jmsFactory); template.setDefaultDestination (activeMQTopic); template.setMessageConverter (new SimpleMessageConverter ()); return template } / * configure message producer * @ return * / @ Bean public PooledConnectionFactory JmsFactory () {return new PooledConnectionFactory ();} / * configure queue message * @ return * / @ Bean public ActiveMQQueue activeMQQueue () {return new ActiveMQQueue () } / * configure topic message * @ return * / @ Bean public ActiveMQTopic activeMQTopic () {return new ActiveMQTopic () } / * configure listeners * @ return * / @ Bean public MessageListener messageListener () {MessageListener messageListener = new MessageListener () {@ Override public void onMessage (Message message) {if (null! = message & & message instanceof TextMessage) {try { (TextMessage) message) .getText () } catch (JMSException e) {e.printStackTrace ();}; return messageListener } / * configure listening container * @ param jmsFactory * @ param activeMQQueue * @ param messageListener * @ return * / @ Bean public DefaultMessageListenerContainer jmsContainer (@ Autowired ConnectionFactory jmsFactory, @ Autowired ActiveMQQueue activeMQQueue) @ Autowired MessageListener messageListener) {DefaultMessageListenerContainer container = new DefaultMessageListenerContainer () Container.setConnectionFactory (jmsFactory); container.setDestination (activeMQQueue); container.setMessageListener (messageListener); return container;}} import org.springframework.beans.factory.annotation.Autowired;import org.springframework.beans.factory.annotation.Qualifier;import org.springframework.jms.core.JmsTemplate;import org.springframework.scheduling.annotation.Async;import org.springframework.stereotype.Service;import javax.jms.TextMessage;@Servicepublic class MQ {@ Autowired@Qualifier ("queueTemplate") private JmsTemplate queueTemplate Autowired@Qualifier ("topicTemplate") private JmsTemplate topicTemplate; @ Async public void queueProducer () {queueTemplate.send (session-> {TextMessage textMessage = session.createTextMessage ("*"); return textMessage;});} @ Async public void queueConsumer () {queueTemplate.receiveAndConvert () } @ Async public void topicProducer () {topicTemplate.send (session-> {TextMessage textMessage = session.createTextMessage ("*"); return textMessage;});} @ Async public void topicConsumer () {topicTemplate.receiveAndConvert () }} the answer to the question about Spring integration MQ configuration is shared here. I hope the above content can be of some help to you. If you still have a lot of doubts to be solved, you can follow the industry information channel to learn more about it.
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.