Rabbitmq 消费者如何根据发布服务器设置的消息优先级获取消息

Rabbitmq 消费者如何根据发布服务器设置的消息优先级获取消息,rabbitmq,spring-rabbit,rabbitmq-exchange,rabbitmq-shovel,Rabbitmq,Spring Rabbit,Rabbitmq Exchange,Rabbitmq Shovel,我为单个使用者(即可能根据消息优先级接收消息的单个使用者)设置了某些优先级的发布消息。 我想要的是获取这些消息,并根据消费者端的消息优先级打印它们。嘿,伙计们,帮帮我 public class Send extends Thread { int priority; String name = ""; String app_type = ""; private static final String EXCHANGE_NAME = "topic_exchange";

我为单个使用者(即可能根据消息优先级接收消息的单个使用者)设置了某些优先级的发布消息。 我想要的是获取这些消息,并根据消费者端的消息优先级打印它们。嘿,伙计们,帮帮我

public class Send extends Thread {

   int priority; 
   String name = "";
   String app_type = "";
   private static final String EXCHANGE_NAME = "topic_exchange";

    public void run()
    {
        ConnectionFactory connFac = new ConnectionFactory();
        connFac.setHost("localhost");

        try {

                Connection conn = connFac.newConnection();
                Channel channel = conn.createChannel();
                channel.exchangeDeclare(EXCHANGE_NAME, 
                BuiltinExchangeType.TOPIC);
                for(int j=1; j<=200; j++)
                {
                    randomWait();

                    int random = (int)(Math.random() * 10 + 1);

                    String routingKey = j+"."+"update"+"."+app_type;
                    String msg = name;
                    channel.basicPublish(EXCHANGE_NAME, routingKey, new 
                    AMQP.BasicProperties.Builder()
                            .contentType("text/plain")
                            .deliveryMode(2)
                            .priority(priority)
                            .build(),
                            msg.getBytes("UTF-8"));
                    System.out.println("Sent " + routingKey + " : " + msg + 
                    " "+" Priority : "+priority);
                }

                channel.close();
                conn.close();

        } catch (IOException ex) {
            Logger.getLogger(Send.class.getName()).log(Level.SEVERE, null, 
             ex);
            System.out.println("Exception1 :--"+ex);

        } catch (TimeoutException ex) {
            Logger.getLogger(Send.class.getName()).log(Level.SEVERE, null, 
          ex);
            System.out.println("Exception 2:--"+ex);
        }
    }

     void randomWait()
    {
        try {
           Thread.currentThread().sleep((long)(200*Math.random()));
        } catch (InterruptedException x) {
           System.out.println("Interrupted!");
        }
    }

   public static void main(String[] args) {
        // TODO code application logic here

        Send test1 = new Send();
        test1.name = "Hello ANDROID";
        test1.app_type = "ANDROID";
        test1.priority = 10;

        Send test2 = new Send();
        test2.name = "Hello ANDROID";
        test2.app_type = "ANDROID";
        test2.priority = 5;

        test1.start();
        test2.start();
    }
}
公共类发送扩展线程{
int优先级;
字符串名称=”;
字符串app_type=“”;
私有静态最终字符串交换\u NAME=“主题交换”;
公开募捐
{
ConnectionFactory connFac=新的ConnectionFactory();
connFac.setHost(“localhost”);
试一试{
连接conn=connFac.newConnection();
Channel=conn.createChannel();
channel.ExchangeClare(交换名称,
BuiltinExchangeType.TOPIC);

对于(int j=1;j队列必须是。

消费者可以根据消息优先级从队列中检索消息。也就是说,假设消费者各自的队列有消息(M1(5)、M2(1)、M3(3)…),现在消费者可以检索M1(5)首先,它具有更高的优先级。是的,当然,只要队列配置正确-请阅读我答案中的文档链接。