@@ -191,7 +191,7 @@ public void handleDelivery(String consumerTag,
191
191
String replyId = properties .getCorrelationId ();
192
192
BlockingCell <Object > blocker = _continuationMap .get (replyId );
193
193
_continuationMap .remove (replyId );
194
- blocker .set (body );
194
+ blocker .set (new Response ( consumerTag , envelope , properties , body ) );
195
195
}
196
196
}
197
197
};
@@ -205,16 +205,15 @@ public void publish(AMQP.BasicProperties props, byte[] message)
205
205
_channel .basicPublish (_exchange , _routingKey , props , message );
206
206
}
207
207
208
- public byte [] primitiveCall (AMQP .BasicProperties props , byte [] message )
209
- throws IOException , ShutdownSignalException , TimeoutException
210
- {
208
+ public Response doCall (AMQP .BasicProperties props , byte [] message )
209
+ throws IOException , ShutdownSignalException , TimeoutException {
211
210
checkConsumer ();
212
211
BlockingCell <Object > k = new BlockingCell <Object >();
213
212
synchronized (_continuationMap ) {
214
213
_correlationId ++;
215
214
String replyId = "" + _correlationId ;
216
215
props = ((props ==null ) ? new AMQP .BasicProperties .Builder () : props .builder ())
217
- .correlationId (replyId ).replyTo (_replyTo ).build ();
216
+ .correlationId (replyId ).replyTo (_replyTo ).build ();
218
217
_continuationMap .put (replyId , k );
219
218
}
220
219
publish (props , message );
@@ -229,10 +228,16 @@ public byte[] primitiveCall(AMQP.BasicProperties props, byte[] message)
229
228
wrapper .initCause (sig );
230
229
throw wrapper ;
231
230
} else {
232
- return (byte [] ) reply ;
231
+ return (Response ) reply ;
233
232
}
234
233
}
235
234
235
+ public byte [] primitiveCall (AMQP .BasicProperties props , byte [] message )
236
+ throws IOException , ShutdownSignalException , TimeoutException
237
+ {
238
+ return doCall (props , message ).getBody ();
239
+ }
240
+
236
241
/**
237
242
* Perform a simple byte-array-based RPC roundtrip.
238
243
* @param message the byte array request message to send
@@ -246,6 +251,21 @@ public byte[] primitiveCall(byte[] message)
246
251
return primitiveCall (null , message );
247
252
}
248
253
254
+ /**
255
+ * Perform a simple byte-array-based RPC roundtrip
256
+ *
257
+ * Useful if you need to get at more than just the body of the message
258
+ *
259
+ * @param message the byte array request message to send
260
+ * @return The response object is an envelope that contains all of the data provided to the `handleDelivery` consumer
261
+ * @throws ShutdownSignalException if the connection dies during our wait
262
+ * @throws IOException if an error is encountered
263
+ * @throws TimeoutException if a response is not received within the configured timeout
264
+ */
265
+ public Response responseCall (byte [] message ) throws IOException , ShutdownSignalException , TimeoutException {
266
+ return doCall (null , message );
267
+ }
268
+
249
269
/**
250
270
* Perform a simple string-based RPC roundtrip.
251
271
* @param message the string request message to send
@@ -368,5 +388,43 @@ public int getCorrelationId() {
368
388
public Consumer getConsumer () {
369
389
return _consumer ;
370
390
}
391
+
392
+ /**
393
+ * The response object is an envelope that contains all of the data provided to the `handleDelivery` consumer
394
+ */
395
+ public static class Response {
396
+ protected String consumerTag ;
397
+ protected Envelope envelope ;
398
+ protected AMQP .BasicProperties properties ;
399
+ protected byte [] body ;
400
+
401
+ public Response () {
402
+ }
403
+
404
+ public Response (
405
+ final String consumerTag , final Envelope envelope , final AMQP .BasicProperties properties ,
406
+ final byte [] body ) {
407
+ this .consumerTag = consumerTag ;
408
+ this .envelope = envelope ;
409
+ this .properties = properties ;
410
+ this .body = body ;
411
+ }
412
+
413
+ public String getConsumerTag () {
414
+ return consumerTag ;
415
+ }
416
+
417
+ public Envelope getEnvelope () {
418
+ return envelope ;
419
+ }
420
+
421
+ public AMQP .BasicProperties getProperties () {
422
+ return properties ;
423
+ }
424
+
425
+ public byte [] getBody () {
426
+ return body ;
427
+ }
428
+ }
371
429
}
372
430
0 commit comments