springboot~rabbitmq本身經過UI手動發佈隊列須要注意的地方

springboot裏發佈隊列消息

爲了兼容性和可讀性更好,咱們通常使用json字符串作爲數據載體。spring

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}

以上兩點注意好,手動發佈隊列就沒有問題了!json

相關文章
相關標籤/搜索