zoukankan      html  css  js  c++  java
  • SpringBoot整合RabbitMQ

    1.配置文件   ---->详情---->移步 https://www.cnblogs.com/zyhzsq/p/13397543.html

    2.发送消息

    public void send(Object message, Map<String, Object> map) {
      MessageHeaders messageHeaders = new MessageHeaders(map);
      Message<?> msg = MessageBuilder.createMessage(message, messageHeaders);
      rabbitTemplate.setConfirmCallback(confirmCallback);
      CorrelationData correlationData = new CorrelationData(UUID.randomUUID().toString());
      rabbitTemplate.convertAndSend("miaosha_exchange", "zyh.miaosha", msg, messagePostProcessor, correlationData);
    }

    3.接收消息

    @RabbitHandler
    @RabbitListener(queues = {"miaosha_queue"})
    public void onMessage(Message message, Channel channel) throws IOException {
    String o = (String) message.getPayload();
    boolean store = ordersService.store(o);
    if (store) {
    channel.basicAck((Long) message.getHeaders().get(AmqpHeaders.DELIVERY_TAG), true);
    System.out.println("消费成功");
    }else{
    channel.basicNack((Long) message.getHeaders().get(AmqpHeaders.DELIVERY_TAG),true,false);
    //
    System.out.println("消息被拒绝");
    }
    }
  • 相关阅读:
    ZOJ Bookcase
    C*++ Calculations
    STL <cctype>
    线段树单点更新+区间更新
    ZOJ Supermarket
    STL <cassert>
    算法导论<二>
    MV Maker [DP]
    LIS 最长有序子序列(递增/递减/非递增/非递减)
    LIS
  • 原文地址:https://www.cnblogs.com/zyhzsq/p/13425586.html
Copyright © 2011-2022 走看看