当前位置: 移动技术网 > IT编程>开发语言>Java > springboot~rabbitmq自己通过UI手动发布队列需要注意的地方

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

2018年10月18日  | 移动技术网IT编程  | 我要评论

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}

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

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网