zoukankan      html  css  js  c++  java
  • rabbitmq学习——主题路由

    public class Send {
    public static final String exchangeName = "topic_logs";
    public static void main(String[] args) throws Exception{
    Connection connection = ChanncelFactory.getChanncelFactory();
    Channel channel = connection.createChannel();

    //主题路由
    channel.exchangeDeclare(exchangeName, "topic");

    String body = "主题路由";
    channel.basicPublish(exchangeName, "com.bonc.ioc", null, body.getBytes());

    ChanncelFactory.close(channel, connection);
    }
    }

    public class Receive {
    public static void main(String[] args) throws Exception {
    Connection connection = ChanncelFactory.getChanncelFactory();
    Channel channel = connection.createChannel();

    channel.exchangeDeclare(Send.exchangeName, "topic");

    String queuename = channel.queueDeclare().getQueue();

    // * 代表一个单词 #代表一个或者多个单词
    channel.queueBind(queuename, Send.exchangeName, "com.#");

    Consumer callback = new DefaultConsumer(channel){
    @Override
    public void handleDelivery(String consumerTag, Envelope envelope,
    BasicProperties properties, byte[] body) throws IOException {
    System.out.println("内容:"+new String(body,"utf-8"));
    }
    };

    for(int i=1; i<6; i++){
    Thread.sleep(2000);
    channel.basicConsume(queuename, true, callback);
    }

    ChanncelFactory.close(channel, connection);
    }
    }

  • 相关阅读:
    bzoj5328: [Sdoi2018]物理实验
    HDU
    bzoj4820: [Sdoi2017]硬币游戏
    bzoj4600: [Sdoi2016]硬币游戏
    阿里云配置防火墙规则
    博客园 添加 Live 2D 模型
    R语言做逻辑回归
    R语言错误的提示(中英文翻译)
    用随机森林分类
    python 切换虚拟环境
  • 原文地址:https://www.cnblogs.com/core404/p/7645269.html
Copyright © 2011-2022 走看看