@@ -43,19 +43,19 @@ public class MulticastParams {
4343 private int producerMsgCount = 0 ;
4444 private int consumerMsgCount = 0 ;
4545
46- private String exchangeName = "" ;
46+ private String exchangeName = "direct " ;
4747 private String exchangeType = "direct" ;
48- private List <String > queueNames = new ArrayList <>();
48+ private List <String > queueNames = new ArrayList <String >();
4949 private String routingKey = null ;
5050 private boolean randomRoutingKey = false ;
5151
52- private List <?> flags = new ArrayList <>();
52+ private List <?> flags = new ArrayList <Object >();
5353
5454 private int multiAckEvery = 0 ;
5555 private boolean autoAck = true ;
5656 private boolean autoDelete = false ;
5757
58- private List <String > bodyFiles = new ArrayList <>();
58+ private List <String > bodyFiles = new ArrayList <String >();
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 <>();
77+ this .queueNames = new ArrayList <String >();
7878 } else {
79- this .queueNames = new ArrayList <>(queueNames );
79+ this .queueNames = new ArrayList <String >(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 <>();
222+ this .bodyFiles = new ArrayList <String >();
223223 } else {
224- this .bodyFiles = new ArrayList <>(bodyFiles );
224+ this .bodyFiles = new ArrayList <String >(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 routingKey ) throws IOException {
232+ public Producer createProducer (Connection connection , Stats stats , String id ) 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 routin
242242 } else {
243243 messageBodySource = new TimeSequenceMessageBodySource (minMsgSize );
244244 }
245- final Producer producer = new Producer (channel , exchangeName , routingKey ,
245+ final Producer producer = new Producer (channel , exchangeName , id ,
246246 randomRoutingKey , flags , producerTxSize ,
247247 producerRateLimit , producerMsgCount ,
248248 timeLimit ,
@@ -252,24 +252,26 @@ public Producer createProducer(Connection connection, Stats stats, String routin
252252 return producer ;
253253 }
254254
255- public Consumer createConsumer (Connection connection , Stats stats , String routingKey ) throws IOException {
255+ public Consumer createConsumer (Connection connection , Stats stats , String id ) throws IOException {
256256 Channel channel = connection .createChannel ();
257257 if (consumerTxSize > 0 ) channel .txSelect ();
258- List <String > generatedQueueNames = configureQueues (connection , routingKey );
258+ List <String > generatedQueueNames = configureQueues (connection , id );
259259 if (consumerPrefetch > 0 ) channel .basicQos (consumerPrefetch );
260260 if (channelPrefetch > 0 ) channel .basicQos (channelPrefetch , true );
261- return new Consumer (channel , routingKey , generatedQueueNames ,
261+ return new Consumer (channel , id , 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.
267269 return consumerCount == 0 && !(queueNames .size () == 0 );
268270 }
269271
270- public List <String > configureQueues (Connection connection , String routingKey ) throws IOException {
272+ public List <String > configureQueues (Connection connection , String id ) throws IOException {
271273 Channel channel = connection .createChannel ();
272- if (!predeclared && !exchangeExists (connection , exchangeName )) {
274+ if (!predeclared || !exchangeExists (connection , exchangeName )) {
273275 channel .exchangeDeclare (exchangeName , exchangeType );
274276 }
275277 // To ensure we get at-least 1 default queue:
@@ -293,7 +295,7 @@ public List<String> configureQueues(Connection connection, String routingKey) th
293295 // skipping binding to default exchange,
294296 // as it's not possible to explicitly bind to it.
295297 if (!"" .equals (exchangeName ) && !"amq.default" .equals (exchangeName )) {
296- channel .queueBind (qName , exchangeName , routingKey );
298+ channel .queueBind (qName , exchangeName , id );
297299 }
298300 }
299301 channel .abort ();
@@ -306,12 +308,20 @@ private static boolean exchangeExists(Connection connection, final String exchan
306308 // NB: default exchange always exists
307309 return true ;
308310 } else {
309- return exists (connection , ch -> ch .exchangeDeclarePassive (exchangeName ));
311+ return exists (connection , new Checker () {
312+ public void check (Channel ch ) throws IOException {
313+ ch .exchangeDeclarePassive (exchangeName );
314+ }
315+ });
310316 }
311317 }
312318
313319 private static boolean queueExists (Connection connection , final String queueName ) throws IOException {
314- return queueName != null && exists (connection , ch -> ch .queueDeclarePassive (queueName ));
320+ return queueName != null && exists (connection , new Checker () {
321+ public void check (Channel ch ) throws IOException {
322+ ch .queueDeclarePassive (queueName );
323+ }
324+ });
315325 }
316326
317327 private interface Checker {
0 commit comments