は春ブーツとのトピックのための第二の容器の工場を設定する方法の完全な例です:
JmsDemoApplication.java:
package net.lenthe;
import javax.jms.ConnectionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.jms.config.DefaultJmsListenerContainerFactory;
@SpringBootApplication
public class JmsDemoApplication {
@Autowired
private ConnectionFactory connectionFactory;
@Bean(name = "topicJmsListenerContainerFactory")
public DefaultJmsListenerContainerFactory getTopicFactory() {
DefaultJmsListenerContainerFactory f = new DefaultJmsListenerContainerFactory();
f.setConnectionFactory(connectionFactory);
f.setSessionTransacted(true);
f.setPubSubDomain(true);
return f;
}
public static void main(String[] args) {
SpringApplication.run(JmsDemoApplication.class, args);
}
}
MessageListenerBean.java:
package net.lenthe;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.jms.annotation.JmsListener;
import org.springframework.stereotype.Component;
@Component
public class MessageListenerBean {
private Logger logger = LoggerFactory.getLogger(this.getClass());
@JmsListener(destination = "myMessageTopic", containerFactory = "topicJmsListenerContainerFactory")
public void processTopicMessage(String content) {
logger.info("Received topic message. Content is " + content);
}
@JmsListener(destination = "myMessageQueue")
public void processQueueMessage(String content) {
logger.info("Received queue message. Content is " + content);
}
}