@@ -18,12 +18,13 @@ public final class AmqpConsumer
18
18
{
19
19
public AmqpConsumer (
20
20
final String host , final Integer port , final String virtualHost , final String username , final String password ,
21
- final String [] exchanges , final String queue , final Callbacks callbacks ,
21
+ final String exchange , final String queue , final String routingKey , final Callbacks callbacks ,
22
22
final LinkedBlockingQueue <AmqpMessage > sink )
23
23
{
24
24
super (host , port , virtualHost , username , password , callbacks );
25
- this .exchanges = exchanges ;
25
+ this .exchange = exchange ;
26
26
this .queue = queue ;
27
+ this .routingKey = routingKey ;
27
28
this .queue1 = null ;
28
29
this .sink = sink ;
29
30
}
@@ -98,14 +99,14 @@ private final void consume (final Envelope envelope, final BasicProperties prope
98
99
private final boolean declare ()
99
100
{
100
101
final Channel channel = this .getChannel ();
101
- for ( final String exchange : this . exchanges ) {
102
- this .callbacks .handleLogEvent (Level .INFO , null , "amqp consumer declaring the exchange `%s`" , exchange );
102
+ {
103
+ this .callbacks .handleLogEvent (Level .INFO , null , "amqp consumer declaring the exchange `%s`" , this . exchange );
103
104
try {
104
- channel .exchangeDeclare (exchange , "topic" , true , false , null );
105
+ channel .exchangeDeclare (this . exchange , "topic" , true , false , null );
105
106
} catch (final Throwable exception ) {
106
107
this .callbacks .handleException (
107
108
exception , "amqp consumer encountered an error while declaring the exchange `%s`; aborting!" ,
108
- exchange );
109
+ this . exchange );
109
110
return (false );
110
111
}
111
112
}
@@ -129,16 +130,16 @@ private final boolean declare ()
129
130
return (false );
130
131
}
131
132
}
132
- for ( final String exchange : this . exchanges ) {
133
+ {
133
134
this .callbacks .handleLogEvent (
134
- Level .INFO , null , "amqp consumer binding the queue `%s` to exchange `%s`" , this .queue1 , exchange );
135
+ Level .INFO , null , "amqp consumer binding the queue `%s` to exchange `%s` with routing key `%s` " , this .queue1 , this . exchange , this . routingKey );
135
136
try {
136
- channel .queueBind (this .queue1 , exchange , "#" , null );
137
+ channel .queueBind (this .queue1 , this . exchange , this . routingKey , null );
137
138
} catch (final Throwable exception ) {
138
139
this .callbacks .handleException (
139
140
exception ,
140
- "amqp consumer encountered an error while binding the queue `%s` to exchange `%s`; aborting!" ,
141
- this .queue1 , exchange );
141
+ "amqp consumer encountered an error while binding the queue `%s` to exchange `%s` with routing key `%s` ; aborting!" ,
142
+ this .queue1 , this . exchange , this . routingKey );
142
143
return (false );
143
144
}
144
145
}
@@ -159,8 +160,9 @@ private final boolean register ()
159
160
}
160
161
}
161
162
162
- private final String [] exchanges ;
163
+ private final String exchange ;
163
164
private final String queue ;
165
+ private final String routingKey ;
164
166
private String queue1 ;
165
167
private final LinkedBlockingQueue <AmqpMessage > sink ;
166
168
0 commit comments