zoukankan      html  css  js  c++  java
  • Rabbitmq发送消息Message的两种写法

    String msg = RandomStringUtils.randomAlphanumeric(6);
    //常规写法
    MessageProperties messageProperties = new MessageProperties();
    messageProperties.setMessageId(UUID.randomUUID().toString());
    messageProperties.setContentType(CONTENT_TYPE_TEXT_PLAIN);
    messageProperties.setContentEncoding("utf8");
    Message message = new Message(msg.getBytes(), messageProperties);
    rabbitTemplate.convertAndSend(topicExchange,"demo.email.x",message);
    
    //lambda 表达式写法
    @FunctionalInterface
    public interface MessagePostProcessor {
        Message postProcessMessage(Message var1) throws AmqpException;
    
        default Message postProcessMessage(Message message, Correlation correlation) {
            return this.postProcessMessage(message);
        }
    }
    //MessagePostProcessor 是函数接口,可以上lambda
    rabbitTemplate.convertAndSend(topicExchange,"demo.email.x",msg,messages->{
        messages.getMessageProperties().setMessageId(UUID.randomUUID().toString());
        messages.getMessageProperties().setContentType(CONTENT_TYPE_TEXT_PLAIN);
        messages.getMessageProperties().setContentEncoding(CharEncoding.UTF_8);
        return messages;
    });
  • 相关阅读:
    python主成分分析
    matplotlib绘图pie
    cpu监控:mpstat命令
    cpu监控:dstat
    MongoDB--安装部署
    Linux-网络管理
    Apache 虚拟主机配置
    Apache 访问控制
    Apache 域名跳转配置
    Apache 日志管理
  • 原文地址:https://www.cnblogs.com/geekdc/p/13539550.html
Copyright © 2011-2022 走看看