2929import java .util .List ;
3030import java .util .SortedSet ;
3131import java .util .TreeSet ;
32+ import java .util .UUID ;
3233import java .util .concurrent .Semaphore ;
3334
3435public class Producer extends ProducerConsumerBase implements Runnable , ReturnListener ,
@@ -37,6 +38,7 @@ public class Producer extends ProducerConsumerBase implements Runnable, ReturnLi
3738 private Channel channel ;
3839 private String exchangeName ;
3940 private String id ;
41+ private boolean randomRKey ;
4042 private boolean mandatory ;
4143 private boolean immediate ;
4244 private boolean persistent ;
@@ -52,7 +54,7 @@ public class Producer extends ProducerConsumerBase implements Runnable, ReturnLi
5254 private volatile SortedSet <Long > unconfirmedSet =
5355 Collections .synchronizedSortedSet (new TreeSet <Long >());
5456
55- public Producer (Channel channel , String exchangeName , String id ,
57+ public Producer (Channel channel , String exchangeName , String id , boolean randomRKey ,
5658 List <?> flags , int txSize ,
5759 float rateLimit , int msgLimit , int minMsgSize , int timeLimit ,
5860 long confirm , Stats stats )
@@ -61,6 +63,7 @@ public Producer(Channel channel, String exchangeName, String id,
6163 this .channel = channel ;
6264 this .exchangeName = exchangeName ;
6365 this .id = id ;
66+ this .randomRKey = randomRKey ;
6467 this .mandatory = flags .contains ("mandatory" );
6568 this .immediate = flags .contains ("immediate" );
6669 this .persistent = flags .contains ("persistent" );
@@ -156,7 +159,7 @@ private void publish(byte[] msg)
156159 throws IOException {
157160
158161 unconfirmedSet .add (channel .getNextPublishSeqNo ());
159- channel .basicPublish (exchangeName , id ,
162+ channel .basicPublish (exchangeName , randomRKey ? UUID . randomUUID (). toString () : id ,
160163 mandatory , immediate ,
161164 persistent ? MessageProperties .MINIMAL_PERSISTENT_BASIC : MessageProperties .MINIMAL_BASIC ,
162165 msg );
0 commit comments