@@ -43,19 +43,19 @@ public class MulticastParams {
4343 private int producerMsgCount = 0 ;
4444 private int consumerMsgCount = 0 ;
4545
46- private String exchangeName = "direct " ;
46+ private String exchangeName = "" ;
4747 private String exchangeType = "direct" ;
48- private List <String > queueNames = new ArrayList <String >();
48+ private List <String > queueNames = new ArrayList <>();
4949 private String routingKey = null ;
5050 private boolean randomRoutingKey = false ;
5151
52- private List <?> flags = new ArrayList <Object >();
52+ private List <?> flags = new ArrayList <>();
5353
5454 private int multiAckEvery = 0 ;
5555 private boolean autoAck = true ;
5656 private boolean autoDelete = false ;
5757
58- private List <String > bodyFiles = new ArrayList <String >();
58+ private List <String > bodyFiles = new ArrayList <>();
5959 private String bodyContentType = null ;
6060
6161 private boolean predeclared ;
@@ -74,9 +74,9 @@ public void setExchangeName(String exchangeName) {
7474
7575 public void setQueueNames (List <String > queueNames ) {
7676 if (queueNames == null ) {
77- this .queueNames = new ArrayList <String >();
77+ this .queueNames = new ArrayList <>();
7878 } else {
79- this .queueNames = new ArrayList <String >(queueNames );
79+ this .queueNames = new ArrayList <>(queueNames );
8080 }
8181 }
8282
@@ -219,21 +219,21 @@ public boolean getRandomRoutingKey() {
219219
220220 public void setBodyFiles (List <String > bodyFiles ) {
221221 if (bodyFiles == null ) {
222- this .bodyFiles = new ArrayList <String >();
222+ this .bodyFiles = new ArrayList <>();
223223 } else {
224- this .bodyFiles = new ArrayList <String >(bodyFiles );
224+ this .bodyFiles = new ArrayList <>(bodyFiles );
225225 }
226226 }
227227
228228 public void setBodyContentType (String bodyContentType ) {
229229 this .bodyContentType = bodyContentType ;
230230 }
231231
232- public Producer createProducer (Connection connection , Stats stats , String id ) throws IOException {
232+ public Producer createProducer (Connection connection , Stats stats , String routingKey ) throws IOException {
233233 Channel channel = connection .createChannel ();
234234 if (producerTxSize > 0 ) channel .txSelect ();
235235 if (confirm >= 0 ) channel .confirmSelect ();
236- if (!predeclared || !exchangeExists (connection , exchangeName )) {
236+ if (!predeclared && !exchangeExists (connection , exchangeName )) {
237237 channel .exchangeDeclare (exchangeName , exchangeType );
238238 }
239239 MessageBodySource messageBodySource = null ;
@@ -242,7 +242,7 @@ public Producer createProducer(Connection connection, Stats stats, String id) th
242242 } else {
243243 messageBodySource = new TimeSequenceMessageBodySource (minMsgSize );
244244 }
245- final Producer producer = new Producer (channel , exchangeName , id ,
245+ final Producer producer = new Producer (channel , exchangeName , routingKey ,
246246 randomRoutingKey , flags , producerTxSize ,
247247 producerRateLimit , producerMsgCount ,
248248 timeLimit ,
@@ -252,26 +252,24 @@ public Producer createProducer(Connection connection, Stats stats, String id) th
252252 return producer ;
253253 }
254254
255- public Consumer createConsumer (Connection connection , Stats stats , String id ) throws IOException {
255+ public Consumer createConsumer (Connection connection , Stats stats , String routingKey ) throws IOException {
256256 Channel channel = connection .createChannel ();
257257 if (consumerTxSize > 0 ) channel .txSelect ();
258- List <String > generatedQueueNames = configureQueues (connection , id );
258+ List <String > generatedQueueNames = configureQueues (connection , routingKey );
259259 if (consumerPrefetch > 0 ) channel .basicQos (consumerPrefetch );
260260 if (channelPrefetch > 0 ) channel .basicQos (channelPrefetch , true );
261- return new Consumer (channel , id , generatedQueueNames ,
261+ return new Consumer (channel , routingKey , generatedQueueNames ,
262262 consumerTxSize , autoAck , multiAckEvery ,
263263 stats , consumerRateLimit , consumerMsgCount , timeLimit , consumerLatencyInMicroseconds );
264264 }
265265
266266 public boolean shouldConfigureQueues () {
267- // don't declare any queues when --predeclared is passed,
268- // otherwise unwanted server-named queues without consumers will pile up. MK.
269267 return consumerCount == 0 && !(queueNames .size () == 0 );
270268 }
271269
272- public List <String > configureQueues (Connection connection , String id ) throws IOException {
270+ public List <String > configureQueues (Connection connection , String routingKey ) throws IOException {
273271 Channel channel = connection .createChannel ();
274- if (!predeclared || !exchangeExists (connection , exchangeName )) {
272+ if (!predeclared && !exchangeExists (connection , exchangeName )) {
275273 channel .exchangeDeclare (exchangeName , exchangeType );
276274 }
277275 // To ensure we get at-least 1 default queue:
@@ -295,7 +293,7 @@ public List<String> configureQueues(Connection connection, String id) throws IOE
295293 // skipping binding to default exchange,
296294 // as it's not possible to explicitly bind to it.
297295 if (!"" .equals (exchangeName ) && !"amq.default" .equals (exchangeName )) {
298- channel .queueBind (qName , exchangeName , id );
296+ channel .queueBind (qName , exchangeName , routingKey );
299297 }
300298 }
301299 channel .abort ();
@@ -308,20 +306,12 @@ private static boolean exchangeExists(Connection connection, final String exchan
308306 // NB: default exchange always exists
309307 return true ;
310308 } else {
311- return exists (connection , new Checker () {
312- public void check (Channel ch ) throws IOException {
313- ch .exchangeDeclarePassive (exchangeName );
314- }
315- });
309+ return exists (connection , ch -> ch .exchangeDeclarePassive (exchangeName ));
316310 }
317311 }
318312
319313 private static boolean queueExists (Connection connection , final String queueName ) throws IOException {
320- return queueName != null && exists (connection , new Checker () {
321- public void check (Channel ch ) throws IOException {
322- ch .queueDeclarePassive (queueName );
323- }
324- });
314+ return queueName != null && exists (connection , ch -> ch .queueDeclarePassive (queueName ));
325315 }
326316
327317 private interface Checker {
0 commit comments