Java 如何使用spring boot连续接收来自IBM MQ JMS的消息?
我有一个spring引导应用程序,它接收JSON请求并将其推送到IBM MQ JMS队列中。可能有n个JSON请求将被推送到队列。我的目标是处理队列中的每个请求。如何侦听队列并使用spring boot逐个处理消息 您需要将侦听器实现为: 1:创建并配置以下内容:Java 如何使用spring boot连续接收来自IBM MQ JMS的消息?,java,spring-boot,ibm-mq,Java,Spring Boot,Ibm Mq,我有一个spring引导应用程序,它接收JSON请求并将其推送到IBM MQ JMS队列中。可能有n个JSON请求将被推送到队列。我的目标是处理队列中的每个请求。如何侦听队列并使用spring boot逐个处理消息 您需要将侦听器实现为: 1:创建并配置以下内容: @Bean public MQConnectionFactory mqConnectionFactory(){ MQConnectionFactory connectionFactory = new MQConnectionFac
@Bean
public MQConnectionFactory mqConnectionFactory(){
MQConnectionFactory connectionFactory = new MQConnectionFactory();
connectionFactory.setHostName(); //mq host name
connectionFactory.setPort(); // mq port
connectionFactory.setQueueManager(); //mq queue manager
connectionFactory.setChannel(); //mq channel name
connectionFactory.setTransportType(1);
connectionFactory.setSSLCipherSuite(); //tls cipher suite name
return connectionFactory;
}
@Bean()
public DefaultMessageListenerContainer myMessageEventContainer() {
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
container.setAutoStartup(true);
container.setConnectionFactory(mqConnectionFactory);
container.setDestinationName(//queue name//);
container.setMessageListener(new MyEventListener());
return container;
}
2:实现消息侦听器:
public class MyEventListener implements MessageListener {
@Override
public void onMessage(Message message) {
try {
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String stringMessage = textMessage.getText();
//do something with your message from queue
}
} catch (JMSException e) {
//catch error
}
}
}
您需要将侦听器实现为: 1:创建并配置以下内容:
@Bean
public MQConnectionFactory mqConnectionFactory(){
MQConnectionFactory connectionFactory = new MQConnectionFactory();
connectionFactory.setHostName(); //mq host name
connectionFactory.setPort(); // mq port
connectionFactory.setQueueManager(); //mq queue manager
connectionFactory.setChannel(); //mq channel name
connectionFactory.setTransportType(1);
connectionFactory.setSSLCipherSuite(); //tls cipher suite name
return connectionFactory;
}
@Bean()
public DefaultMessageListenerContainer myMessageEventContainer() {
DefaultMessageListenerContainer container = new DefaultMessageListenerContainer();
container.setAutoStartup(true);
container.setConnectionFactory(mqConnectionFactory);
container.setDestinationName(//queue name//);
container.setMessageListener(new MyEventListener());
return container;
}
2:实现消息侦听器:
public class MyEventListener implements MessageListener {
@Override
public void onMessage(Message message) {
try {
if (message instanceof TextMessage) {
TextMessage textMessage = (TextMessage) message;
String stringMessage = textMessage.getText();
//do something with your message from queue
}
} catch (JMSException e) {
//catch error
}
}
}
在pom.xml中添加“mq jms spring boot starter”依赖项,如下所示: 在application.yaml中添加以下属性:
mq:
queue-manager: queueManager
conn-name: connName(port)
channel: channelName
ssl-cipher-suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 or whatever ur app supports
use-i-b-m-cipher-mappings: true (if using topic otherwise skip this property)
将下面的注释@JmsListener添加到侦听器方法中
@EnableJms
Public class Consumer{
@JmsListener(destination = "QueueNameToListenTo")
public void listener(Object message) {
logger.info("message received {}",message);
//do something
}
}
在pom.xml中添加“mq jms spring boot starter”依赖项,如下所示: 在application.yaml中添加以下属性:
mq:
queue-manager: queueManager
conn-name: connName(port)
channel: channelName
ssl-cipher-suite: TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384 or whatever ur app supports
use-i-b-m-cipher-mappings: true (if using topic otherwise skip this property)
将下面的注释@JmsListener添加到侦听器方法中
@EnableJms
Public class Consumer{
@JmsListener(destination = "QueueNameToListenTo")
public void listener(Object message) {
logger.info("message received {}",message);
//do something
}
}
我在使用IBM Mq创建spring启动应用程序时遇到了问题。由于我无法连接到Websphere MQ,请您帮助我。我在使用IBM MQ创建spring启动应用程序时面临问题。我无法连接到Websphere MQ,请您帮助我。