English 中文(简体)
如何为Rabbitmq的电文确定基本信息特性?
原标题:how to set the basic message properties for message in Rabbitmq?
  • 时间:2010-11-11 06:59:34
  •  标签:
  • rabbitmq

i 正在利用Rabbitmq Java客户Amend.i制作电文的基本财产,并获取电文的电文。 如果有可能,请提供一些法规来了解情况。

增 编

最佳回答

在通过java客户发送电文时,信息通常会公布到像一个渠道。

 CHANNEL.basicPublish(EXCHANGE_NAME, QUEUE_ROUTING_KEY, MessageProperties.PERSISTENT_TEXT_PLAIN, "message".getBytes)

在这里,你可以传递信息。

You can get the msg by using a delivery agent You have to first bind the queue like this

 Channel channel = conn.createChannel();
      String exchangeName = "myExchange";
      String queueName = "myQueue";
      String routingKey = "testRoute"; 
      boolean durable = true;
      channel.exchangeDeclare(exchangeName, "direct", durable);
      channel.queueDeclare(queueName, durable,false,false,durable, null);
channel.queueBind(queueName, exchangeName, routingKey);
      boolean noAck = false;
      QueueingConsumer consumer = new QueueingConsumer(channel);
      channel.basicConsume(queueName, noAck, consumer);

然后使用衰竭才能获得ms

QueueingConsumer.Delivery delivery;
            try {
               delivery = consumer.nextDelivery();

            } catch (InterruptedException ie) {
               continue;
            }
问题回答

如何做到这一点:

int PERSISTENCE_MESSAGE = 2; // Persist message
String TEXT_MESSAGE = "text/plain";
String queueName = "QUE-1";

Channel channel = this.connection.createChannel();
channel.queueDeclare(queueName, true, false, false, null);

// Build message properties
Map messageProps = new HashMap();
//messageProps.put("TIME_MSG_RECEIVED", time);
messageProps.put("SOURCE_SYS", "SRC1");
messageProps.put("DESTINATION_SYS", "DST1");

// Set message properties
AMQP.BasicProperties.Builder basicProperties = new AMQP.BasicProperties.Builder();
basicProperties.contentType(TEXT_MESSAGE).deliveryMode(PERSISTENCE_MESSAGE)
.priority(1).headers(messageProps);

channel.basicPublish("", queueName,  basicProperties.build(), message.getBytes());
System.out.println(" Sent message to RabbitMQ:  " + message + " ");
channel.close();




相关问题
what the default max length of rabbit queue

For any given queue, the maximum length (of either type) can be defined using a policy (this option is highly recommended) or by clients using the queue s optional arguments. In the case where both ...

Retrieve messages from RabbitMQ queue(s)

I m looking to implement RabbitMQ into my PHP application, and am using the php-amqp extension. My only question is this, how do I easily query to return the contents of the queue in PHP? php-amqp ...

How to use listen on basic.return in python client of AMQP

I d like to make sure that my message was delivered to a queue. To do so I m adding the mandatory param to the basic_publish. What else should I do to receive the basic.return message if my message ...

Is AMQP production ready?

I d like to use AMQP to join two services one written in C# and other written in python. I m expecting quite large volume of messages per second. Is there any AMQP Broker that is production ready? ...

Multiple consumer one queue

Is it possible to make multiple consumers to share one single queue in RabbitMQ? I am currently using this php library to work with RabbitMQ, from what I observe, although I have 2 identical instances ...

Why use AMQP/ZeroMQ/RabbitMQ

as opposed to writing your own library. We re working on a project here that will be a self-dividing server pool, if one section grows too heavy, the manager would divide it and put it on another ...

How to wait for messages on multiple queues using py-amqplib

I m using py-amqplib to access RabbitMQ in Python. The application receives requests to listen on certain MQ topics from time to time. The first time it receives such a request it creates an AMQP ...

热门标签