Skip to content

Commit 0bd8e91

Browse files
authored
Merge pull request #257 from rabbitmq/rename-rpc-to-request-response
Rename RpcClient/RpcServer to Requester/Responder
2 parents cdaf625 + 6e75586 commit 0bd8e91

File tree

13 files changed

+274
-273
lines changed

13 files changed

+274
-273
lines changed

src/docs/asciidoc/usage.adoc

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -165,106 +165,106 @@ rabbitmq_amqp_published_released_total 1.0
165165
rabbitmq_amqp_publishers 1.0
166166
------
167167

168-
=== Remote Procedure Call (RPC)
168+
=== Request/Response
169169

170-
Remote procedure call with RabbitMQ consists in a client sending a request message and a server replying with a response message.
171-
Both the RPC client and server are _client applications_ and the messages flow through the broker.
172-
The RPC client must send a reply-to queue address with the request.
173-
The RPC server uses this reply-to queue address to send the response.
174-
There must also be a way to correlate a request with its response, this is usually handled with a header that the RPC client and server agree on.
170+
Request/response with RabbitMQ consists in a requester sending a request message and a responder replying with a response message.
171+
Both the requester and responder are _client applications_ and the messages flow through the broker.
172+
The requester must send a reply-to queue address with the request.
173+
The responder uses this reply-to queue address to send the response.
174+
There must also be a way to correlate a request with its response, this is usually handled with a header that the requester and responder agree on.
175175

176-
The library provides RPC client and server support classes.
176+
The library provides requester and responder support classes.
177177
They use sensible defaults and some of the internal mechanics are configurable.
178-
They should meet the requirements of most RPC use cases.
179-
It is still possible to implement one part or the other with regular publishers and consumers for special cases, as this is what the RPC support classes do.
178+
They should meet the requirements of most request/response use cases.
179+
It is still possible to implement one part or the other with regular publishers and consumers for special cases, as this is what the request/response support classes do.
180180

181-
Here is how to create an RPC server instance:
181+
Here is how to create a responder instance:
182182

183-
.Creating an RPC server
183+
.Creating a responder
184184
[source,java,indent=0]
185185
--------
186-
include::{test-examples}/RpcApi.java[tag=rpc-server-creation]
186+
include::{test-examples}/RequestResponseApi.java[tag=responder-creation]
187187
--------
188188
<1> Use builder from connection
189189
<2> Set the queue to consume requests from (it must exist)
190190
<3> Define the processing logic
191191
<4> Create the reply message
192192

193-
Note the RPC server does not create the queue it waits requests on.
193+
Note the responder does not create the queue it waits requests on.
194194
It must be created beforehand.
195195

196-
Here is how to create an RPC client:
196+
Here is how to create a requester:
197197

198-
.Creating an RPC client
198+
.Creating a requester
199199
[source,java,indent=0]
200200
--------
201-
include::{test-examples}/RpcApi.java[tag=rpc-client-creation]
201+
include::{test-examples}/RequestResponseApi.java[tag=requester-creation]
202202
--------
203203
<1> Use builder from connection
204204
<2> Set the address to send request messages to
205205

206-
The RPC client will send its request to the configured destination.
206+
The requester will send its request to the configured destination.
207207
It can be an exchange or a queue, like in the example above.
208208

209209
Here is how to send a request:
210210

211211
.Sending a request
212212
[source,java,indent=0]
213213
--------
214-
include::{test-examples}/RpcApi.java[tag=rpc-client-request]
214+
include::{test-examples}/RequestResponseApi.java[tag=requester-request]
215215
--------
216216
<1> Create the message request
217217
<2> Send the request
218218
<3> Wait for the reply (synchronously)
219219

220-
The `RpcClient#publish(Message)` method returns a `CompletableFuture<Message>` that holds the reply message.
220+
The `Requester#publish(Message)` method returns a `CompletableFuture<Message>` that holds the reply message.
221221
It is then possible to wait for the reply asynchronously or synchronously.
222222

223-
The RPC server has the following behavior:
223+
The responder has the following behavior:
224224

225225
* when receiving a message request, it calls the processing logic (handler), extracts the correlation ID, calls a reply post-processor if defined, and sends the reply message.
226-
* if all these operations succeed, the server accepts the request message (settles it with the `ACCEPTED` outcome).
227-
* if any of these operations throws an exception, the server discards the request message (the message is removed from the request queue and is https://www.rabbitmq.com/client-libraries/amqp-client-libraries#message-processing-result-outcome[dead-lettered] if configured).
226+
* if all these operations succeed, the responder accepts the request message (settles it with the `ACCEPTED` outcome).
227+
* if any of these operations throws an exception, the responder discards the request message (the message is removed from the request queue and is https://www.rabbitmq.com/client-libraries/amqp-client-libraries#message-processing-result-outcome[dead-lettered] if configured).
228228

229-
The RPC server uses the following defaults:
229+
The responder uses the following defaults:
230230

231231
* it uses the _request_ https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-properties[`message-id` property] for the correlation ID.
232232
* it assigns the correlation ID (so the _request_ `message-id` by default) to the _reply_ https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-properties[`correlation-id` property].
233233
* it assigns the _request_ https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-properties[`reply-to` property] to the _reply_ https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-properties[`to` property] if it is defined.
234-
This behavior is hardcoded but it is possible to cancel it thanks to a reply post-processor.
234+
This behavior is hardcoded, but it is possible to override it thanks to a reply post-processor.
235235

236-
The RPC client uses the following defaults:
236+
The requester uses the following defaults:
237237

238238
* it uses https://www.rabbitmq.com/docs/direct-reply-to[direct reply-to] if available (RabbitMQ 4.2 or more) for replies if no reply-to queue is set (it falls back to an auto-delete, exclusive queue if direct reply-to is not available)
239239
* it uses a string-based correlation ID generator, with a fixed random UUID prefix and a strictly monotonic increasing sequence suffix (`{UUID}-{sequence}`, e.g. `6f839461-6b19-47e1-80b3-6be10d899d85-42`).
240-
The prefix is different for each `RpcClient` instance and the suffix is incremented by one for each request.
240+
The prefix is different for each `Requester` instance and the suffix is incremented by one for each request.
241241
* it sets the _request_ https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-properties[`reply-to` property] to the reply-to queue address (defined by the user or created automatically, see above).
242242
* it sets the _request_ https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-properties[`message-id` property] to the generated correlation ID.
243243
* it extracts the correlation ID from the _reply_ https://docs.oasis-open.org/amqp/core/v1.0/os/amqp-core-messaging-v1.0-os.html#type-properties[`correlation-id` property] to correlate a reply with the appropriate request.
244244

245-
Let's see how to customize some of the RPC support mechanics.
245+
Let's see how to customize some of the request/response support mechanics.
246246
Imagine the request `message-id` property is a critical piece of information and we do not want to use it as the correlation ID.
247-
The request can use the `correlation-id` property and the RPC server just has to extract the correlation ID from this property (instead of the `message-id` property by default).
247+
The request can use the `correlation-id` property and the responder just has to extract the correlation ID from this property (instead of the `message-id` property by default).
248248
Let's also use a random UUID for the correlation ID generation (avoids doing this in production: this is OK in terms of uniqueness but not optimal in terms of performance because randomness is not cheap).
249249

250-
Here is how to declare the RPC client:
250+
Here is how to declare the requester:
251251

252-
.Customizing the RPC client
252+
.Customizing the requester
253253
[source,java,indent=0]
254254
--------
255-
include::{test-examples}/RpcApi.java[tag=rpc-custom-client-creation]
255+
include::{test-examples}/RequestResponseApi.java[tag=custom-requester-creation]
256256
--------
257257
<1> Declare the reply-to queue
258258
<2> Use a random UUID as correlation ID
259259
<3> Use the `correlation-id` property for the request
260260
<4> Set the `reply-to` property
261261
<5> Set the address to send request messages to
262262

263-
We just have to tell the RPC server to get the correlation ID from the request `correlation-id` property:
263+
We just have to tell the responder to get the correlation ID from the request `correlation-id` property:
264264

265-
.Customizing the RPC server
265+
.Customizing the responder
266266
[source,java,indent=0]
267267
--------
268-
include::{test-examples}/RpcApi.java[tag=rpc-custom-server-creation]
268+
include::{test-examples}/RequestResponseApi.java[tag=custom-responder-creation]
269269
--------
270270
<1> Get the correlation ID from the request `correlation-id` property

src/main/java/com/rabbitmq/client/amqp/Connection.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -44,18 +44,18 @@ public interface Connection extends Closeable, Resource {
4444
ConsumerBuilder consumerBuilder();
4545

4646
/**
47-
* Create a builder to configure and create a {@link RpcClientBuilder}.
47+
* Create a builder to configure and create a {@link RequesterBuilder}.
4848
*
49-
* @return RPC client builder
49+
* @return requester builder
5050
*/
51-
RpcClientBuilder rpcClientBuilder();
51+
RequesterBuilder requesterBuilder();
5252

5353
/**
54-
* Create a builder to configure and create a {@link RpcServerBuilder}.
54+
* Create a builder to configure and create a {@link Responder}.
5555
*
56-
* @return RPC server builder
56+
* @return responder builder
5757
*/
58-
RpcServerBuilder rpcServerBuilder();
58+
ResponderBuilder responderBuilder();
5959

6060
/** Close the connection and its resources */
6161
@Override

src/main/java/com/rabbitmq/client/amqp/RpcClient.java renamed to src/main/java/com/rabbitmq/client/amqp/Requester.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,11 +20,11 @@
2020
import java.util.concurrent.CompletableFuture;
2121

2222
/**
23-
* Client support class for RPC.
23+
* Requester support class for request/response interaction.
2424
*
25-
* @see RpcClientBuilder
25+
* @see RequesterBuilder
2626
*/
27-
public interface RpcClient extends AutoCloseable {
27+
public interface Requester extends AutoCloseable {
2828

2929
/**
3030
* Create a message meant to be published by the underlying publisher instance.
@@ -55,7 +55,7 @@ public interface RpcClient extends AutoCloseable {
5555
*/
5656
CompletableFuture<Message> publish(Message message);
5757

58-
/** Close the RPC client and its resources. */
58+
/** Close the requester and its resources. */
5959
@Override
6060
void close();
6161
}

src/main/java/com/rabbitmq/client/amqp/RpcClientBuilder.java renamed to src/main/java/com/rabbitmq/client/amqp/RequesterBuilder.java

Lines changed: 15 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -22,27 +22,28 @@
2222
import java.util.function.Function;
2323
import java.util.function.Supplier;
2424

25-
/** API to configure and create a {@link RpcClient}. */
26-
public interface RpcClientBuilder {
25+
/** API to configure and create a {@link Requester}. */
26+
public interface RequesterBuilder {
2727

2828
/**
2929
* Builder for the request address.
3030
*
3131
* @return the request address builder
3232
*/
33-
RpcClientAddressBuilder requestAddress();
33+
RequesterAddressBuilder requestAddress();
3434

3535
/**
3636
* The queue the client expects responses on.
3737
*
3838
* <p>The queue <b>must</b> exist if it is set.
3939
*
40-
* <p>The RPC client will create an exclusive, auto-delete queue if it is not set.
40+
* <p>The requester will a direct reply-to queue (RabbitMQ 4.2 or more) or create an exclusive,
41+
* auto-delete queue if this parameter is not set.
4142
*
4243
* @param replyToQueue reply queue
4344
* @return this builder instance
4445
*/
45-
RpcClientBuilder replyToQueue(String replyToQueue);
46+
RequesterBuilder replyToQueue(String replyToQueue);
4647

4748
/**
4849
* The generator for correlation ID.
@@ -53,7 +54,7 @@ public interface RpcClientBuilder {
5354
* @param correlationIdSupplier correlation ID generator
5455
* @return the this builder instance
5556
*/
56-
RpcClientBuilder correlationIdSupplier(Supplier<Object> correlationIdSupplier);
57+
RequesterBuilder correlationIdSupplier(Supplier<Object> correlationIdSupplier);
5758

5859
/**
5960
* A callback before sending a request message.
@@ -67,7 +68,7 @@ public interface RpcClientBuilder {
6768
* @param requestPostProcessor logic to post-process request message
6869
* @return this builder instance
6970
*/
70-
RpcClientBuilder requestPostProcessor(BiFunction<Message, Object, Message> requestPostProcessor);
71+
RequesterBuilder requestPostProcessor(BiFunction<Message, Object, Message> requestPostProcessor);
7172

7273
/**
7374
* Callback to extract the correlation ID from a reply message.
@@ -80,31 +81,31 @@ public interface RpcClientBuilder {
8081
* @param correlationIdExtractor correlation ID extractor
8182
* @return this builder instance
8283
*/
83-
RpcClientBuilder correlationIdExtractor(Function<Message, Object> correlationIdExtractor);
84+
RequesterBuilder correlationIdExtractor(Function<Message, Object> correlationIdExtractor);
8485

8586
/**
8687
* Timeout before failing outstanding requests.
8788
*
8889
* @param timeout timeout
8990
* @return the builder instance
9091
*/
91-
RpcClientBuilder requestTimeout(Duration timeout);
92+
RequesterBuilder requestTimeout(Duration timeout);
9293

9394
/**
9495
* Build the configured instance.
9596
*
9697
* @return the configured instance
9798
*/
98-
RpcClient build();
99+
Requester build();
99100

100101
/** Builder for the request address. */
101-
interface RpcClientAddressBuilder extends AddressBuilder<RpcClientAddressBuilder> {
102+
interface RequesterAddressBuilder extends AddressBuilder<RequesterAddressBuilder> {
102103

103104
/**
104-
* Go back to the RPC client builder.
105+
* Go back to the requester builder.
105106
*
106-
* @return the RPC client builder
107+
* @return the requester builder
107108
*/
108-
RpcClientBuilder rpcClient();
109+
RequesterBuilder requester();
109110
}
110111
}

src/main/java/com/rabbitmq/client/amqp/RpcServer.java renamed to src/main/java/com/rabbitmq/client/amqp/Responder.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,11 @@
1818
package com.rabbitmq.client.amqp;
1919

2020
/**
21-
* Client server class for RPC.
21+
* Responder class for request/response interaction.
2222
*
23-
* @see RpcServerBuilder
23+
* @see ResponderBuilder
2424
*/
25-
public interface RpcServer extends AutoCloseable {
25+
public interface Responder extends AutoCloseable {
2626

2727
/** Contract to process a request message and return a reply message. */
2828
@FunctionalInterface
@@ -87,7 +87,7 @@ interface Context {
8787
/** Request to receive messages again. */
8888
void unpause();
8989

90-
/** Close the RPC server and its resources. */
90+
/** Close the responder and its resources. */
9191
@Override
9292
void close();
9393
}

src/main/java/com/rabbitmq/client/amqp/RpcServerBuilder.java renamed to src/main/java/com/rabbitmq/client/amqp/ResponderBuilder.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,24 @@
2121
import java.util.function.BiFunction;
2222
import java.util.function.Function;
2323

24-
/** API to configure and create a {@link RpcServer}. */
25-
public interface RpcServerBuilder {
24+
/** API to configure and create a {@link Responder}. */
25+
public interface ResponderBuilder {
2626

2727
/**
2828
* The queue to wait for requests on.
2929
*
3030
* @param requestQueue request queue
3131
* @return this builder instance
3232
*/
33-
RpcServerBuilder requestQueue(String requestQueue);
33+
ResponderBuilder requestQueue(String requestQueue);
3434

3535
/**
3636
* The logic to process requests and issue replies.
3737
*
3838
* @param handler handler
3939
* @return this builder instance
4040
*/
41-
RpcServerBuilder handler(RpcServer.Handler handler);
41+
ResponderBuilder handler(Responder.Handler handler);
4242

4343
/**
4444
* Logic to extract the correlation ID from a request message.
@@ -48,7 +48,7 @@ public interface RpcServerBuilder {
4848
* @param correlationIdExtractor logic to extract the correlation ID
4949
* @return this builder instance
5050
*/
51-
RpcServerBuilder correlationIdExtractor(Function<Message, Object> correlationIdExtractor);
51+
ResponderBuilder correlationIdExtractor(Function<Message, Object> correlationIdExtractor);
5252

5353
/**
5454
* A callback called after request processing but before sending the reply message.
@@ -61,7 +61,7 @@ public interface RpcServerBuilder {
6161
* @param replyPostProcessor logic to post-process reply message
6262
* @return this builder instance
6363
*/
64-
RpcServerBuilder replyPostProcessor(BiFunction<Message, Object, Message> replyPostProcessor);
64+
ResponderBuilder replyPostProcessor(BiFunction<Message, Object, Message> replyPostProcessor);
6565

6666
/**
6767
* The time the server waits for all outstanding requests to be processed before closing.
@@ -73,12 +73,12 @@ public interface RpcServerBuilder {
7373
* @param closeTimeout close timeout
7474
* @return this builder instance
7575
*/
76-
RpcServerBuilder closeTimeout(Duration closeTimeout);
76+
ResponderBuilder closeTimeout(Duration closeTimeout);
7777

7878
/**
7979
* Create the configured instance.
8080
*
8181
* @return the configured instance
8282
*/
83-
RpcServer build();
83+
Responder build();
8484
}

0 commit comments

Comments
 (0)