@@ -17,10 +17,10 @@ public static void main(String[] argv) {
17
17
System .err .println ("Usage: ReceiveLogsHeader queueName [headers]..." );
18
18
System .exit (1 );
19
19
}
20
-
20
+
21
21
ConnectionFactory factory = new ConnectionFactory ();
22
22
factory .setHost ("localhost" );
23
-
23
+
24
24
connection = factory .newConnection ();
25
25
channel = connection .createChannel ();
26
26
@@ -30,14 +30,14 @@ public static void main(String[] argv) {
30
30
// value of the routing key is not used in the routing. You can receive information
31
31
// from the sender here as the routing key is still available in the received message.
32
32
String routingKeyFromUser = "ourTestRoutingKey" ;
33
-
33
+
34
34
// Argument processing: the first arg is the local queue name, the rest are
35
35
// key value pairs for headers.
36
36
String queueInputName = argv [0 ];
37
37
38
38
// The map for the headers.
39
39
Map <String , Object > headers = new HashMap <String , Object >();
40
-
40
+
41
41
// The rest of the arguments are key value header pairs. For the purpose of this
42
42
// example, we are assuming they are all strings, but that is not required by RabbitMQ
43
43
// 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) {
51
51
52
52
String queueName = channel .queueDeclare (queueInputName , true , false , false , null ).getQueue ();
53
53
channel .queueBind (queueName , EXCHANGE_NAME , routingKeyFromUser , headers );
54
-
54
+
55
55
System .out .println (" [*] Waiting for messages. To exit press CTRL+C" );
56
56
57
57
QueueingConsumer consumer = new QueueingConsumer (channel );
58
58
channel .basicConsume (queueName , true , consumer );
59
59
60
60
while (true ) {
61
61
QueueingConsumer .Delivery delivery = consumer .nextDelivery ();
62
- String message = new String (delivery .getBody ());
62
+ String message = new String (delivery .getBody (), "UTF-8" );
63
63
String routingKeyFromSender = delivery .getEnvelope ().getRoutingKey ();
64
64
65
- System .out .println (" [x] Received '" + routingKeyFromSender + "':'" + message + "'" );
65
+ System .out .println (" [x] Received '" + routingKeyFromSender + "':'" + message + "'" );
66
66
}
67
67
}
68
68
catch (Exception e ) {
0 commit comments