2525import org .springframework .core .task .TaskExecutor ;
2626
2727import java .io .IOException ;
28- import java .util .HashMap ;
2928import java .util .Map ;
3029import java .util .concurrent .ConcurrentHashMap ;
3130
@@ -64,19 +63,24 @@ public void declareExchangeAndBind(String exchange,
6463 }
6564
6665 public void declare (String queue , boolean durable ) throws IOException {
67- this .channel .queueDeclare (queue , durable , false , false , null );
66+ this .channel .queueDeclare (queue , durable , false , false , Map .of (
67+ "x-single-active-consumer" , true
68+ ));
6869 }
6970
7071 public void declareTemp (String queue ) throws IOException {
71- this .channel .queueDeclare (queue , false , false , true , null );
72+ this .channel .queueDeclare (queue , false , false , true , Map .of (
73+ "x-single-active-consumer" , true
74+ ));
7275 }
7376
7477 public void declare (String queue , boolean durable , Integer maxPriority , String dlExName ) throws IOException {
75- Map <String , Object > props = new HashMap <>(3 );
76- props .put ("x-max-priority" , maxPriority );
77- props .put ("x-dead-letter-exchange" , dlExName );
78- props .put ("x-dead-letter-routing-key" , QueueConfig .JobDlRoutingKey );
79- this .channel .queueDeclare (queue , durable , false , false , props );
78+ this .channel .queueDeclare (queue , durable , false , false , Map .of (
79+ "x-max-priority" , maxPriority ,
80+ "x-dead-letter-exchange" , dlExName ,
81+ "x-dead-letter-routing-key" , QueueConfig .JobDlRoutingKey ,
82+ "x-single-active-consumer" , true
83+ ));
8084 }
8185
8286 public boolean delete (String queue ) {
@@ -108,9 +112,9 @@ public boolean sendToEx(String ex, byte[] body, Map<String, Object> headers) {
108112 }
109113
110114 /**
111- * Send to routing key with default exchange
115+ * Publish data with routing key to default exchange
112116 */
113- public boolean send (String routingKey , byte [] body ) {
117+ public boolean publish (String routingKey , byte [] body ) {
114118 try {
115119 this .channel .basicPublish (StringHelper .EMPTY , routingKey , null , body );
116120 return true ;
@@ -120,9 +124,9 @@ public boolean send(String routingKey, byte[] body) {
120124 }
121125
122126 /**
123- * Send to routing key with default exchange and priority
127+ * Publish data with routing key and priority to default exchange
124128 */
125- public boolean send (String routingKey , byte [] body , Integer priority , int expireInSecond ) {
129+ public boolean publish (String routingKey , byte [] body , Integer priority , int expireInSecond ) {
126130 try {
127131 AMQP .BasicProperties props = new AMQP .BasicProperties .Builder ()
128132 .priority (priority )
0 commit comments