Skip to content

Commit 8d2e8f2

Browse files
committed
docs(handler): update queue handling documentation for consistency and clarity
1 parent 51ffd18 commit 8d2e8f2

File tree

7 files changed

+79
-27
lines changed

7 files changed

+79
-27
lines changed

acceptance/async-tests/src/test/java/org/reactivecommons/test/QueryProcessPerfTest.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,7 @@
1818

1919
import java.util.List;
2020
import java.util.Map;
21-
import java.util.concurrent.CountDownLatch;
2221
import java.util.concurrent.Semaphore;
23-
import java.util.concurrent.atomic.AtomicLong;
24-
import java.util.stream.Collectors;
2522
import java.util.stream.IntStream;
2623

2724
import static reactor.core.publisher.Flux.range;
@@ -32,8 +29,6 @@ class QueryProcessPerfTest {
3229
private static final String QUERY_NAME = "app.command.test";
3330
private static final int MESSAGE_COUNT = 40000;
3431
private static final Semaphore semaphore = new Semaphore(0);
35-
// private static final AtomicLong atomicLong = new AtomicLong(0);
36-
// private static final CountDownLatch latch = new CountDownLatch(12 + 1);
3732

3833
@Autowired
3934
private DirectAsyncGateway gateway;

async/async-rabbit/src/main/java/org/reactivecommons/async/rabbit/listeners/ApplicationQueueListener.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,3 @@ protected String getKind() {
5353
return "queue";
5454
}
5555
}
56-
57-
58-

docs/docs/migration-guides.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ sidebar_position: 4
66

77
## From 5.x.x to 6.x.x
88

9-
### New Features
9+
### New features
1010

1111
- **Connection customization:** You can now customize the RabbitMQ connection by defining a
1212
`ConnectionFactoryCustomizer` bean. For more details,
@@ -92,7 +92,7 @@ public class MyDomainConfig {
9292

9393
## From 4.x.x to 5.x.x
9494

95-
### New Features
95+
### New features
9696

9797
- **Support for multiple brokers:** It is now possible to configure and connect to up to two brokers simultaneously,
9898
using

docs/docs/reactive-commons/11-creating-a-cloud-event.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ CloudEvent eventCloudEvent = CloudEventBuilder.v1()
5757
.build();
5858
```
5959

60-
## Creating a CloudEvent instance with jackson wrapper Data wrapper
60+
## Creating a CloudEvent instance with Jackson wrapper Data wrapper
6161

6262
add this classes:
6363

docs/docs/reactive-commons/8-handling-queues.md

Lines changed: 74 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ sidebar_position: 8
88

99
To listen to a custom queue you should register it in the HandlerRegistry and make it available as a Bean. Queue listeners provide direct access to RabbitMQ queues with full control over queue configuration and topology.
1010

11-
### Listening Queues
11+
### Listening queues
1212

1313
The simplest way to listen to a queue is by providing the queue name and a handler:
1414

@@ -19,7 +19,7 @@ public class HandlerRegistryConfiguration {
1919
@Bean
2020
public HandlerRegistry handlerRegistry(QueueHandler queueHandler) {
2121
return HandlerRegistry.register()
22-
.listenQueue("my.custom.queue", queueHandler::handleQueueMessage);
22+
.listenQueue("my.custom.queue", queueHandler::handleMessage);
2323
}
2424
}
2525
```
@@ -30,7 +30,7 @@ To effectively start listening to queues you should add the annotation `@EnableQ
3030
@EnableQueueListeners
3131
public class QueueHandler {
3232

33-
public Mono<Void> handleQueueMessage(RawMessage message) {
33+
public Mono<Void> handleMessage(RawMessage message) {
3434
RabbitMessage rawMessage = (RabbitMessage) message;
3535
System.out.println("Message received from queue: " + new String(rawMessage.getBody()));
3636
System.out.println("Headers: " + rawMessage.getProperties().getHeaders());
@@ -40,7 +40,7 @@ public class QueueHandler {
4040
}
4141
```
4242

43-
### Listening Queues with Custom Topology
43+
### Listening queues with custom topology
4444

4545
If you need to configure the queue topology (exchange type, durability, bindings, etc.), you can use the `TopologyHandlerSetup` parameter:
4646

@@ -51,7 +51,7 @@ public class HandlerRegistryConfiguration {
5151
@Bean
5252
public HandlerRegistry handlerRegistry(QueueHandler queueHandler) {
5353
return HandlerRegistry.register()
54-
.listenQueue("my.custom.queue", queueHandler::handleQueueMessage, topologyCreator -> {
54+
.listenQueue("my.custom.queue", queueHandler::handleMessage, topologyCreator -> {
5555
var creator = (TopologyCreator) topologyCreator;
5656

5757
var exchangeSpecification = ExchangeSpecification
@@ -88,7 +88,7 @@ The `TopologyHandlerSetup` allows you to:
8888
- Set queue types (classic, quorum)
8989
- Set queue properties like durability, auto-delete, and exclusivity
9090

91-
### Listening Queues with Custom Domain
91+
### Listening queues with custom domain
9292

9393
You can listen to queues in different domains by specifying the domain name:
9494

@@ -99,19 +99,19 @@ public class HandlerRegistryConfiguration {
9999
@Bean
100100
public HandlerRegistry handlerRegistry(QueueHandler queueHandler) {
101101
return HandlerRegistry.register()
102-
.listenQueue("customDomain", "my.custom.queue", queueHandler::handleQueueMessage);
102+
.listenQueue("customDomain", "my.custom.queue", queueHandler::handleMessage);
103103
}
104104
}
105105
```
106106

107-
## Queue Configuration Examples
107+
## Queue configuration examples
108108

109-
### Dead Letter Queue Configuration
109+
### Dead letter queue configuration
110110

111111
Configure a queue with a dead letter exchange for failed messages:
112112

113113
```java
114-
.listenQueue("main.queue", handler::handleMessage, topologyCreator -> {
114+
.listenQueue("main.queue", queueHandler::handleMessage, topologyCreator -> {
115115
var creator = (TopologyCreator) topologyCreator;
116116

117117
var mainQueue = QueueSpecification.queue("main.queue")
@@ -143,12 +143,12 @@ Configure a queue with a dead letter exchange for failed messages:
143143
})
144144
```
145145

146-
### Priority Queue Configuration
146+
### Priority queue configuration
147147

148148
Configure a priority queue:
149149

150150
```java
151-
.listenQueue("priority.queue", handler::handleMessage, topologyCreator -> {
151+
.listenQueue("priority.queue", queueHandler::handleMessage, topologyCreator -> {
152152
var creator = (TopologyCreator) topologyCreator;
153153

154154
var queueSpec = QueueSpecification.queue("priority.queue")
@@ -159,12 +159,12 @@ Configure a priority queue:
159159
})
160160
```
161161

162-
### Quorum Queue Configuration
162+
### Quorum queue configuration
163163

164164
Configure a quorum queue for high availability:
165165

166166
```java
167-
.listenQueue("quorum.queue", handler::handleMessage, topologyCreator -> {
167+
.listenQueue("quorum.queue", queueHandler::handleMessage, topologyCreator -> {
168168
var creator = (TopologyCreator) topologyCreator;
169169

170170
var queueSpec = QueueSpecification.queue("quorum.queue")
@@ -177,3 +177,63 @@ Configure a quorum queue for high availability:
177177
return creator.declare(queueSpec).then();
178178
})
179179
```
180+
181+
### Temporary queue configuration
182+
183+
Configure a temporary queue with a random name for short-lived, exclusive connections. Temporary queues are useful for reply-to patterns or ephemeral consumers:
184+
185+
```java
186+
@Configuration
187+
public class HandlerRegistryConfiguration {
188+
189+
@Bean
190+
public HandlerRegistry handlerRegistry(QueueHandler queueHandler) {
191+
String queueName = "temp.queue.".concat(generateRandomQueueName());
192+
193+
return HandlerRegistry.register()
194+
.listenQueue(queueName, queueHandler::handleMessage, topologyCreator -> {
195+
var creator = (TopologyCreator) topologyCreator;
196+
String exchangeName = "temp.exchange";
197+
198+
var exchangeSpec = ExchangeSpecification.exchange(exchangeName)
199+
.type("topic")
200+
.durable(true);
201+
202+
var queueSpec = QueueSpecification.queue(queueName)
203+
.durable(false)
204+
.autoDelete(true)
205+
.exclusive(true);
206+
207+
var binding = creator.bind(
208+
BindingSpecification.binding(exchangeName, queueName, queueName)
209+
);
210+
211+
return creator.declare(exchangeSpec)
212+
.then(creator.declare(queueSpec))
213+
.then(binding)
214+
.then();
215+
});
216+
}
217+
218+
private String generateRandomQueueName() {
219+
UUID uuid = UUID.randomUUID();
220+
ByteBuffer bb = ByteBuffer.wrap(new byte[16]);
221+
bb.putLong(uuid.getMostSignificantBits())
222+
.putLong(uuid.getLeastSignificantBits());
223+
// Convert to base64 and remove trailing =
224+
return encodeToUrlSafeString(bb.array())
225+
.replace("=", "");
226+
}
227+
228+
private static String encodeToUrlSafeString(byte[] src) {
229+
return new String(encodeUrlSafe(src));
230+
}
231+
232+
private static byte[] encodeUrlSafe(byte[] src) {
233+
if (src.length == 0) {
234+
return src;
235+
}
236+
return Base64.getUrlEncoder().encode(src);
237+
}
238+
}
239+
```

docs/docs/reactive-commons/9-serving-async-queries.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class HandlerRegistryConfiguration {
5454

5555
So any consumer can send a query with a name that matches with pattern, for example: `my.some.query`
5656

57-
### Delegated Queries
57+
### Delegated queries
5858

5959
There is a concept introduced in queries that cannot be resolved locally and may require a later answer, in that case we are in front of the next scenario:
6060

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
{
22
"label": "Configuration Properties",
3-
"position": 9
3+
"position": 12
44
}

0 commit comments

Comments
 (0)