@@ -17,10 +17,10 @@ public static void main(String[] argv) {
1717 System .err .println ("Usage: ReceiveLogsHeader queueName [headers]..." );
1818 System .exit (1 );
1919 }
20-
20+
2121 ConnectionFactory factory = new ConnectionFactory ();
2222 factory .setHost ("localhost" );
23-
23+
2424 connection = factory .newConnection ();
2525 channel = connection .createChannel ();
2626
@@ -30,14 +30,14 @@ public static void main(String[] argv) {
3030 // value of the routing key is not used in the routing. You can receive information
3131 // from the sender here as the routing key is still available in the received message.
3232 String routingKeyFromUser = "ourTestRoutingKey" ;
33-
33+
3434 // Argument processing: the first arg is the local queue name, the rest are
3535 // key value pairs for headers.
3636 String queueInputName = argv [0 ];
3737
3838 // The map for the headers.
3939 Map <String , Object > headers = new HashMap <String , Object >();
40-
40+
4141 // The rest of the arguments are key value header pairs. For the purpose of this
4242 // example, we are assuming they are all strings, but that is not required by RabbitMQ
4343 // Note that when you run this code you should include the x-match header on the command
@@ -51,18 +51,18 @@ public static void main(String[] argv) {
5151
5252 String queueName = channel .queueDeclare (queueInputName , true , false , false , null ).getQueue ();
5353 channel .queueBind (queueName , EXCHANGE_NAME , routingKeyFromUser , headers );
54-
54+
5555 System .out .println (" [*] Waiting for messages. To exit press CTRL+C" );
5656
5757 QueueingConsumer consumer = new QueueingConsumer (channel );
5858 channel .basicConsume (queueName , true , consumer );
5959
6060 while (true ) {
6161 QueueingConsumer .Delivery delivery = consumer .nextDelivery ();
62- String message = new String (delivery .getBody ());
62+ String message = new String (delivery .getBody (), "UTF-8" );
6363 String routingKeyFromSender = delivery .getEnvelope ().getRoutingKey ();
6464
65- System .out .println (" [x] Received '" + routingKeyFromSender + "':'" + message + "'" );
65+ System .out .println (" [x] Received '" + routingKeyFromSender + "':'" + message + "'" );
6666 }
6767 }
6868 catch (Exception e ) {
0 commit comments