springboot~rabbitmq自己通过UI手动发布队列需要注意的地方

栏目: Java · 发布时间: 7年前

内容简介:为了兼容性和可读性更好,我们一般使用json字符串做为数据载体。以上两点注意好,手动发布队列就没有问题了!

springboot里发布队列消息

为了兼容性和可读性更好,我们一般使用json字符串做为数据载体。

public void decreaseCallMonitor(CallMonitorInfo callMonitorInfo) throws Exception {
    try {
      rabbitTemplate.convertAndSend(
          AmqpConfig.DATA_COLLECTION_EXCHANGE,
          AmqpConfig.CALLMONITOR_DECREASE_BINDING,
          objectMapper.writeValueAsString(callMonitorInfo)
      );
      logger.debug("Enter {},message:{}", "decreaseCallMonitor", callMonitorInfo.toString());

    } catch (Exception ex) {
      logger.error("MQ.decreaseCallMonitor.error", ex);
    }
  }

springboot里订阅消息

@RabbitHandler
  @RabbitListener(queues = AmqpConfig.CUSTOMER_TERMINATE_BINDING)
  public void customerTerminate(String data) {
    try {
      TerminateDTO terminateDTO = objectMapper.readValue(data, TerminateDTO.class);
      customerBusinessInfoMapper.updateCustomer_business_info(ImmutableMap.of(
          "status", EnumCustomerStatus.TERMINATE.getCode(),
          "customerId", terminateDTO.getCustomerId()
      ));
    } catch (Exception ex) {
      logger.error("解约同步异常", ex);
    }
  }

通过UI15672手动发消息要注意的地方

  1. 添加properties,声明它是utf-8及文本类型
content_encoding:utf-8
content_type:text/plain
  1. json字符串需要压缩,把回车换行都去掉,否则会出错
{"signSalespersonId":1001,"signSalesperson":"mq","signTime":null,"customerId":501806811767111700}

以上两点注意好,手动发布队列就没有问题了!


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Web Design for ROI

Web Design for ROI

Lance Loveday、Sandra Niehaus / New Riders Press / 2007-10-27 / USD 39.99

Your web site is a business--design it like one. Billions of dollars in spending decisions are influenced by web sites. So why aren't businesses laser-focused on designing their sites to maximize thei......一起来看看 《Web Design for ROI》 这本书的介绍吧!

JS 压缩/解压工具
JS 压缩/解压工具

在线压缩/解压 JS 代码

XML 在线格式化
XML 在线格式化

在线 XML 格式化压缩工具