AMQP-RabbitMQ/5/主题模式

  1. 云栖社区>
  2. 博客>
  3. 正文

AMQP-RabbitMQ/5/主题模式

futaosmile 2019-06-08 08:30:25 浏览549
展开阅读全文

5. 主题模式 Topics

根据主题接收消息

routing_key - 它必须是由英文点.分隔的单词列表

  • *可以替代一个单词。
  • 可以替换零个或多个单词。
  • 图示

主题模式

个人理解

  • 路由模式基本相同,不同的点只是路由模式需要Queue订阅的路由键与消息的路由键完全匹配,Exchange才会将消息发送给Queue。
  • 而主题模式(Exchange类型为topic),消费者在将Exchange与Queue绑定时设置的路由键可以有通配。
  • 生产者
package com.futao.springmvcdemo.mq.rabbit.topic;

import com.futao.springmvcdemo.mq.rabbit.ExchangeTypeEnum;
import com.futao.springmvcdemo.mq.rabbit.RabbitMqConnectionTools;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import lombok.Cleanup;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * Topic模式-生产者
 *
 * @author futao
 * Created on 2019-04-22.
 */
@Slf4j
public class Producer {
    @SneakyThrows
    public static void main(String[] args) {
        @Cleanup
        Connection connection = RabbitMqConnectionTools.getConnection();
        @Cleanup
        Channel channel = connection.createChannel();
        //定义交换器类型
        channel.exchangeDeclare(ExchangeTypeEnum.TOPIC.getExchangeName(), BuiltinExchangeType.TOPIC);
        String msg = "Hello RabbitMq!";
        for (int i = 0; i < 10; i++) {
            channel.basicPublish(ExchangeTypeEnum.TOPIC.getExchangeName(), "log.info", null, (msg + i + "log.info").getBytes());
            log.info("Send msg:[{}] ,routingKey:[{}] success", (msg + i + "log.info"), "log.info");
        }
        for (int i = 0; i < 10; i++) {
            channel.basicPublish(ExchangeTypeEnum.TOPIC.getExchangeName(), "log.error", null, (msg + i + "log.error").getBytes());
            log.info("Send msg:[{}] ,routingKey:[{}] success", (msg + i + "log.error"), "log.error");
        }
        for (int i = 0; i < 10; i++) {
            channel.basicPublish(ExchangeTypeEnum.TOPIC.getExchangeName(), "log.error.rabbitmq", null, (msg + i + "log.error.rabbitmq").getBytes());
            log.info("Send msg:[{}] ,routingKey:[{}] success", (msg + i + "log.error.rabbitmq"), "log.error.rabbitmq");
        }
    }
}
  • 消费者1 - 订阅log.error and log.info
package com.futao.springmvcdemo.mq.rabbit.topic;

import com.futao.springmvcdemo.mq.rabbit.ExchangeTypeEnum;
import com.futao.springmvcdemo.mq.rabbit.RabbitMqConnectionTools;
import com.futao.springmvcdemo.mq.rabbit.RabbitMqQueueEnum;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * Topic模式-消费者1
 *
 * @author futao
 * Created on 2019-04-22.
 */
@Slf4j
public class ConsumerOne {
    @SneakyThrows
    public static void main(String[] args) {
        Channel channel = RabbitMqConnectionTools.getChannel();
        //开启持久化队列
        boolean durable = true;
        channel.queueDeclare(RabbitMqQueueEnum.EXCHANGE_QUEUE_TOPIC_ONE.getQueueName(), durable, false, false, null);
        //定义交换器类型
        channel.exchangeDeclare(ExchangeTypeEnum.DIRECT.getExchangeName(), BuiltinExchangeType.TOPIC);
        //将消息队列与Exchange交换器与路由键绑定(同时订阅路由key为"log.info"和"log.error"的消息)
        channel.queueBind(RabbitMqQueueEnum.EXCHANGE_QUEUE_TOPIC_ONE.getQueueName(), ExchangeTypeEnum.TOPIC.getExchangeName(), "log.error");
        channel.queueBind(RabbitMqQueueEnum.EXCHANGE_QUEUE_TOPIC_ONE.getQueueName(), ExchangeTypeEnum.TOPIC.getExchangeName(), "log.info");
        //告诉rabbitmq一次只发送一条消息,并且在前一个消息未被处理或者消费之前,不继续发送下一个消息
        channel.basicQos(1);
        log.info("Waiting for message...");
        DeliverCallback deliverCallback = ((consumerTag, message) -> {
            log.info("收到消息:[{}],routingKey:[{}],tag:[{}]", new String(message.getBody()), message.getEnvelope().getRoutingKey(), consumerTag);
            //acknowledgment应答
            channel.basicAck(message.getEnvelope().getDeliveryTag(), false);
            try {
                Thread.sleep(1000);
            } catch (Exception e) {

            }
        });
        //关闭自动应答
        boolean autoAck = false;
        channel.basicConsume(RabbitMqQueueEnum.EXCHANGE_QUEUE_TOPIC_ONE.getQueueName(), autoAck, deliverCallback, consumerTag -> {
        });
    }
}
  • 消费者2 - 订阅log.error
package com.futao.springmvcdemo.mq.rabbit.topic;

import com.futao.springmvcdemo.mq.rabbit.ExchangeTypeEnum;
import com.futao.springmvcdemo.mq.rabbit.RabbitMqConnectionTools;
import com.futao.springmvcdemo.mq.rabbit.RabbitMqQueueEnum;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * Topic模式-消费者2
 *
 * @author futao
 * Created on 2019-04-22.
 */
@Slf4j
public class ConsumerTwo {
    @SneakyThrows
    public static void main(String[] args) {
        Channel channel = RabbitMqConnectionTools.getChannel();
        //开启持久化队列
        boolean durable = true;
        channel.queueDeclare(RabbitMqQueueEnum.EXCHANGE_QUEUE_TOPIC_TWO.getQueueName(), durable, false, false, null);
        //定义交换器类型
        channel.exchangeDeclare(ExchangeTypeEnum.TOPIC.getExchangeName(), BuiltinExchangeType.TOPIC);
        //将消息队列与Exchange交换器进行绑定(只订阅路由key为"log.error"的消息)
        channel.queueBind(RabbitMqQueueEnum.EXCHANGE_QUEUE_TOPIC_TWO.getQueueName(), ExchangeTypeEnum.TOPIC.getExchangeName(), "log.error");
        //告诉rabbitmq一次只发送一条消息,并且在前一个消息未被处理或者消费之前,不继续发送下一个消息
        channel.basicQos(1);
        log.info("Waiting for message...");
        DeliverCallback deliverCallback = ((consumerTag, message) -> {
            log.info("收到消息:[{}],routingKey:[{}],tag:[{}]", new String(message.getBody()), message.getEnvelope().getRoutingKey(), consumerTag);
            //acknowledgment应答
            channel.basicAck(message.getEnvelope().getDeliveryTag(), false);
            try {
                Thread.sleep(2000);
            } catch (Exception e) {

            }
        });
        //关闭自动应答
        boolean autoAck = false;
        channel.basicConsume(RabbitMqQueueEnum.EXCHANGE_QUEUE_TOPIC_TWO.getQueueName(), autoAck, deliverCallback, consumerTag -> {
        });
    }
}
  • 消费者3 - 订阅log.*
package com.futao.springmvcdemo.mq.rabbit.topic;

import com.futao.springmvcdemo.mq.rabbit.ExchangeTypeEnum;
import com.futao.springmvcdemo.mq.rabbit.RabbitMqConnectionTools;
import com.futao.springmvcdemo.mq.rabbit.RabbitMqQueueEnum;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * Topic模式-消费者3
 *
 * @author futao
 * Created on 2019-04-22.
 */
@Slf4j
public class ConsumerThree {
    @SneakyThrows
    public static void main(String[] args) {
        Channel channel = RabbitMqConnectionTools.getChannel();
        //开启持久化队列
        boolean durable = true;
        channel.queueDeclare(RabbitMqQueueEnum.EXCHANGE_QUEUE_TOPIC_THREE.getQueueName(), durable, false, false, null);
        //定义交换器类型
        channel.exchangeDeclare(ExchangeTypeEnum.DIRECT.getExchangeName(), BuiltinExchangeType.TOPIC);
        //将消息队列与Exchange交换器与路由键绑定(同时订阅路由key为"log.info"和"log.error"的消息)
        channel.queueBind(RabbitMqQueueEnum.EXCHANGE_QUEUE_TOPIC_THREE.getQueueName(), ExchangeTypeEnum.TOPIC.getExchangeName(), "log.*");
        //告诉rabbitmq一次只发送一条消息,并且在前一个消息未被处理或者消费之前,不继续发送下一个消息
        channel.basicQos(1);
        log.info("Waiting for message...");
        DeliverCallback deliverCallback = ((consumerTag, message) -> {
            log.info("收到消息:[{}],routingKey:[{}],tag:[{}]", new String(message.getBody()), message.getEnvelope().getRoutingKey(), consumerTag);
            //acknowledgment应答
            channel.basicAck(message.getEnvelope().getDeliveryTag(), false);
            try {
                Thread.sleep(1000);
            } catch (Exception e) {

            }
        });
        //关闭自动应答
        boolean autoAck = false;
        channel.basicConsume(RabbitMqQueueEnum.EXCHANGE_QUEUE_TOPIC_THREE.getQueueName(), autoAck, deliverCallback, consumerTag -> {
        });
    }
}
  • 消费者4 - 订阅log.#
package com.futao.springmvcdemo.mq.rabbit.topic;

import com.futao.springmvcdemo.mq.rabbit.ExchangeTypeEnum;
import com.futao.springmvcdemo.mq.rabbit.RabbitMqConnectionTools;
import com.futao.springmvcdemo.mq.rabbit.RabbitMqQueueEnum;
import com.rabbitmq.client.BuiltinExchangeType;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.DeliverCallback;
import lombok.SneakyThrows;
import lombok.extern.slf4j.Slf4j;

/**
 * Topic模式-消费者4
 *
 * @author futao
 * Created on 2019-04-22.
 */
@Slf4j
public class ConsumerFour {
    @SneakyThrows
    public static void main(String[] args) {
        Channel channel = RabbitMqConnectionTools.getChannel();
        //开启持久化队列
        boolean durable = true;
        channel.queueDeclare(RabbitMqQueueEnum.EXCHANGE_QUEUE_TOPIC_FOUR.getQueueName(), durable, false, false, null);
        //定义交换器类型
        channel.exchangeDeclare(ExchangeTypeEnum.DIRECT.getExchangeName(), BuiltinExchangeType.TOPIC);
        //将消息队列与Exchange交换器与路由键绑定(同时订阅路由key为"log.info"和"log.error"的消息)
        channel.queueBind(RabbitMqQueueEnum.EXCHANGE_QUEUE_TOPIC_FOUR.getQueueName(), ExchangeTypeEnum.TOPIC.getExchangeName(), "log.#");
        //告诉rabbitmq一次只发送一条消息,并且在前一个消息未被处理或者消费之前,不继续发送下一个消息
        channel.basicQos(1);
        log.info("Waiting for message...");
        DeliverCallback deliverCallback = ((consumerTag, message) -> {
            log.info("收到消息:[{}],routingKey:[{}],tag:[{}]", new String(message.getBody()), message.getEnvelope().getRoutingKey(), consumerTag);
            //acknowledgment应答
            channel.basicAck(message.getEnvelope().getDeliveryTag(), false);
            try {
                Thread.sleep(1000);
            } catch (Exception e) {

            }
        });
        //关闭自动应答
        boolean autoAck = false;
        channel.basicConsume(RabbitMqQueueEnum.EXCHANGE_QUEUE_TOPIC_FOUR.getQueueName(), autoAck, deliverCallback, consumerTag -> {
        });
    }
}
  • 测试
>>> 生产者-生产主题分别为:`log.info` and `log.error` and `log.error.rabbitmq`的消息
略

>>> 消费者1 - 订阅`log.error` and `log.info`
19:42:31.130 [main] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - Waiting for message...
19:42:48.506 [pool-1-thread-4] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!0log.info],routingKey:[log.info],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:42:49.509 [pool-1-thread-5] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!1log.info],routingKey:[log.info],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:42:50.513 [pool-1-thread-6] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!2log.info],routingKey:[log.info],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:42:51.517 [pool-1-thread-7] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!3log.info],routingKey:[log.info],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:42:52.520 [pool-1-thread-8] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!4log.info],routingKey:[log.info],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:42:53.524 [pool-1-thread-9] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!5log.info],routingKey:[log.info],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:42:54.529 [pool-1-thread-10] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!6log.info],routingKey:[log.info],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:42:55.535 [pool-1-thread-11] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!7log.info],routingKey:[log.info],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:42:56.539 [pool-1-thread-12] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!8log.info],routingKey:[log.info],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:42:57.540 [pool-1-thread-13] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!9log.info],routingKey:[log.info],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:42:58.545 [pool-1-thread-14] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!0log.error],routingKey:[log.error],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:42:59.551 [pool-1-thread-15] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!1log.error],routingKey:[log.error],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:43:00.556 [pool-1-thread-16] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!2log.error],routingKey:[log.error],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:43:01.560 [pool-1-thread-17] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!3log.error],routingKey:[log.error],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:43:02.561 [pool-1-thread-18] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!4log.error],routingKey:[log.error],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:43:03.566 [pool-1-thread-19] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!5log.error],routingKey:[log.error],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:43:04.569 [pool-1-thread-20] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!6log.error],routingKey:[log.error],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:43:05.572 [pool-1-thread-21] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!7log.error],routingKey:[log.error],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:43:06.574 [pool-1-thread-22] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!8log.error],routingKey:[log.error],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]
19:43:07.580 [pool-1-thread-23] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerOne - 收到消息:[Hello RabbitMq!9log.error],routingKey:[log.error],tag:[amq.ctag-YQRXOwb2xsoODmB2fpJ1Qg]

>>> 消费者2 - 订阅`log.error` 
19:42:36.272 [main] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerTwo - Waiting for message...
19:42:48.516 [pool-1-thread-4] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerTwo - 收到消息:[Hello RabbitMq!0log.error],routingKey:[log.error],tag:[amq.ctag-Q3m55Q8-XWC-SlF1qX80cA]
19:42:50.522 [pool-1-thread-5] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerTwo - 收到消息:[Hello RabbitMq!1log.error],routingKey:[log.error],tag:[amq.ctag-Q3m55Q8-XWC-SlF1qX80cA]
19:42:52.523 [pool-1-thread-6] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerTwo - 收到消息:[Hello RabbitMq!2log.error],routingKey:[log.error],tag:[amq.ctag-Q3m55Q8-XWC-SlF1qX80cA]
19:42:54.527 [pool-1-thread-7] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerTwo - 收到消息:[Hello RabbitMq!3log.error],routingKey:[log.error],tag:[amq.ctag-Q3m55Q8-XWC-SlF1qX80cA]
19:42:56.529 [pool-1-thread-8] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerTwo - 收到消息:[Hello RabbitMq!4log.error],routingKey:[log.error],tag:[amq.ctag-Q3m55Q8-XWC-SlF1qX80cA]
19:42:58.533 [pool-1-thread-9] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerTwo - 收到消息:[Hello RabbitMq!5log.error],routingKey:[log.error],tag:[amq.ctag-Q3m55Q8-XWC-SlF1qX80cA]
19:43:00.534 [pool-1-thread-10] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerTwo - 收到消息:[Hello RabbitMq!6log.error],routingKey:[log.error],tag:[amq.ctag-Q3m55Q8-XWC-SlF1qX80cA]
19:43:02.539 [pool-1-thread-11] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerTwo - 收到消息:[Hello RabbitMq!7log.error],routingKey:[log.error],tag:[amq.ctag-Q3m55Q8-XWC-SlF1qX80cA]
19:43:04.541 [pool-1-thread-12] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerTwo - 收到消息:[Hello RabbitMq!8log.error],routingKey:[log.error],tag:[amq.ctag-Q3m55Q8-XWC-SlF1qX80cA]
19:43:06.543 [pool-1-thread-13] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerTwo - 收到消息:[Hello RabbitMq!9log.error],routingKey:[log.error],tag:[amq.ctag-Q3m55Q8-XWC-SlF1qX80cA]

>>> 消费者3 - 订阅`log.*`
19:42:39.746 [main] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - Waiting for message...
19:42:48.507 [pool-1-thread-4] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!0log.info],routingKey:[log.info],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:42:49.509 [pool-1-thread-5] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!1log.info],routingKey:[log.info],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:42:50.513 [pool-1-thread-6] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!2log.info],routingKey:[log.info],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:42:51.517 [pool-1-thread-7] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!3log.info],routingKey:[log.info],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:42:52.520 [pool-1-thread-8] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!4log.info],routingKey:[log.info],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:42:53.524 [pool-1-thread-9] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!5log.info],routingKey:[log.info],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:42:54.529 [pool-1-thread-10] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!6log.info],routingKey:[log.info],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:42:55.535 [pool-1-thread-11] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!7log.info],routingKey:[log.info],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:42:56.539 [pool-1-thread-12] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!8log.info],routingKey:[log.info],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:42:57.540 [pool-1-thread-13] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!9log.info],routingKey:[log.info],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:42:58.545 [pool-1-thread-14] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!0log.error],routingKey:[log.error],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:42:59.551 [pool-1-thread-15] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!1log.error],routingKey:[log.error],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:43:00.556 [pool-1-thread-16] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!2log.error],routingKey:[log.error],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:43:01.560 [pool-1-thread-17] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!3log.error],routingKey:[log.error],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:43:02.561 [pool-1-thread-18] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!4log.error],routingKey:[log.error],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:43:03.566 [pool-1-thread-19] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!5log.error],routingKey:[log.error],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:43:04.569 [pool-1-thread-20] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!6log.error],routingKey:[log.error],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:43:05.572 [pool-1-thread-21] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!7log.error],routingKey:[log.error],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:43:06.574 [pool-1-thread-22] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!8log.error],routingKey:[log.error],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]
19:43:07.580 [pool-1-thread-23] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerThree - 收到消息:[Hello RabbitMq!9log.error],routingKey:[log.error],tag:[amq.ctag-0-_1m0BhTsYpjikUjsWEQA]


>>> 消费者4 - 订阅`log.#`
19:42:42.624 [main] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - Waiting for message...
19:42:48.506 [pool-1-thread-4] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!0log.info],routingKey:[log.info],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:42:49.509 [pool-1-thread-5] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!1log.info],routingKey:[log.info],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:42:50.513 [pool-1-thread-6] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!2log.info],routingKey:[log.info],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:42:51.517 [pool-1-thread-7] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!3log.info],routingKey:[log.info],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:42:52.520 [pool-1-thread-8] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!4log.info],routingKey:[log.info],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:42:53.524 [pool-1-thread-9] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!5log.info],routingKey:[log.info],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:42:54.529 [pool-1-thread-10] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!6log.info],routingKey:[log.info],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:42:55.535 [pool-1-thread-11] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!7log.info],routingKey:[log.info],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:42:56.539 [pool-1-thread-12] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!8log.info],routingKey:[log.info],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:42:57.540 [pool-1-thread-13] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!9log.info],routingKey:[log.info],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:42:58.545 [pool-1-thread-14] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!0log.error],routingKey:[log.error],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:42:59.551 [pool-1-thread-15] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!1log.error],routingKey:[log.error],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:00.556 [pool-1-thread-16] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!2log.error],routingKey:[log.error],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:01.560 [pool-1-thread-17] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!3log.error],routingKey:[log.error],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:02.561 [pool-1-thread-18] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!4log.error],routingKey:[log.error],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:03.566 [pool-1-thread-19] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!5log.error],routingKey:[log.error],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:04.569 [pool-1-thread-20] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!6log.error],routingKey:[log.error],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:05.572 [pool-1-thread-21] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!7log.error],routingKey:[log.error],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:06.574 [pool-1-thread-22] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!8log.error],routingKey:[log.error],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:07.580 [pool-1-thread-23] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!9log.error],routingKey:[log.error],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:08.586 [pool-1-thread-24] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!0log.error.rabbitmq],routingKey:[log.error.rabbitmq],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:09.587 [pool-1-thread-25] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!1log.error.rabbitmq],routingKey:[log.error.rabbitmq],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:10.589 [pool-1-thread-26] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!2log.error.rabbitmq],routingKey:[log.error.rabbitmq],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:11.593 [pool-1-thread-26] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!3log.error.rabbitmq],routingKey:[log.error.rabbitmq],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:12.599 [pool-1-thread-26] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!4log.error.rabbitmq],routingKey:[log.error.rabbitmq],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:13.602 [pool-1-thread-26] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!5log.error.rabbitmq],routingKey:[log.error.rabbitmq],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:14.605 [pool-1-thread-26] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!6log.error.rabbitmq],routingKey:[log.error.rabbitmq],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:15.607 [pool-1-thread-26] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!7log.error.rabbitmq],routingKey:[log.error.rabbitmq],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:16.608 [pool-1-thread-26] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!8log.error.rabbitmq],routingKey:[log.error.rabbitmq],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]
19:43:17.609 [pool-1-thread-26] INFO com.futao.springmvcdemo.mq.rabbit.topic.ConsumerFour - 收到消息:[Hello RabbitMq!9log.error.rabbitmq],routingKey:[log.error.rabbitmq],tag:[amq.ctag-Ml8Iiz8KSEh4RBn4yfA0xA]

网友评论

登录后评论
0/500
评论
futaosmile
+ 关注