springboot 同时监听queue和topic

自定义两个ContainerFactory,setPubSubDomain(false)为监听queue,setPubSubDomain(true)为监听topic;

@Bean

public DefaultJmsListenerContainerFactory queueListenerFactory(){

    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();

    factory.setConnectionFactory(connectionFactory);

    factory.setPubSubDomain(false);

    return factory;

}

@Bean

public DefaultJmsListenerContainerFactory topicListenerFactory(){

    DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();

    factory.setConnectionFactory(connectionFactory);

    factory.setPubSubDomain(true);

    return factory;

}

监听队列时指定@JmsListener的containerFactory为上面定义的queueListenerFactory

@JmsListener(destination="${newsedit.queue}",containerFactory="queueListenerFactory")

public voidreceiveQueueMsg(String text){

    try{

        PublishServiceQueueMsg msg =mapper.readValue(text,PublishServiceQueueMsg.class);

        msgHandler.handler(msg);

    }catch(IOException e) {

        logger.error("receiveQueueMsg error!",e);

        e.printStackTrace();

    }

}

监听主题时指定@JmsListener的containerFactory为上面定义的topicListenerFactory

@JmsListener(destination="${newsedit.topic}",containerFactory="topicListenerFactory")

public voidreceiveTopicMsg(String text){

    try{

        PublishServiceTopicMsg msg =mapper.readValue(text,PublishServiceTopicMsg.class);

        msgHandler.handler(msg);

    }catch(IOException e) {

        logger.error("receiveTopicMsg error!",e);

        e.printStackTrace();

    }

}

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • Spring Cloud为开发人员提供了快速构建分布式系统中一些常见模式的工具(例如配置管理,服务发现,断路器,智...
    卡卡罗2017阅读 134,845评论 18 139
  • 本文章翻译自http://www.rabbitmq.com/api-guide.html,并没有及时更新。 术语对...
    joyenlee阅读 7,695评论 0 3
  • ActiveMQ 即时通讯服务 浅析http://www.cnblogs.com/hoojo/p/active_m...
    bboymonk阅读 1,513评论 0 11
  • 2017年5月17日 Kylin_Wu 标注(★☆)为考纲明确给出考点(必考) 常见手机系统(★☆) And...
    Azur_wxj阅读 1,833评论 0 10
  • 在信息过载的时代,如何合理接收信息成了很重的一项技能,我们都读了很多年的书,好像似乎没有学过如何选好书,如何去读书...
    goen8715阅读 744评论 1 1