diff --git a/README.md b/README.md index 45f6153..7553c85 100644 --- a/README.md +++ b/README.md @@ -29,6 +29,9 @@ See the client at: - [rpc/simple/rx-rpc.html](rpc/simple/rx-rpc.html). - Click the button `Submit Problem` many times to see each one getting submitted as independent requests. +- There is an alternate client sample at + [rpc/simple/rx-rpc-explicit-return-dest.html](rpc/simple/rx-rpc-explicit-return-dest.html). + This uses custom reply queue. This client is only tested with the simple ruby server. You will need to run at least one of the following servers: diff --git a/rpc/ruby-server/simple-server.rb b/rpc/ruby-server/simple-server.rb index 3a2a2f1..150af2a 100644 --- a/rpc/ruby-server/simple-server.rb +++ b/rpc/ruby-server/simple-server.rb @@ -15,7 +15,6 @@ # rpc-server-thread-pool.rb ############################################################################### - amqp_conn = Bunny.new amqp_conn.start @@ -29,7 +28,7 @@ # Process the request, compute the response operands = JSON.parse(payload) - result = {result: operands['x'].to_i + operands['y'].to_i} + result = { result: operands['x'].to_i + operands['y'].to_i } response_body = result.to_json # Completed processing @@ -37,5 +36,13 @@ default_exchange = channel.default_exchange - default_exchange.publish response_body, routing_key: metadata[:reply_to], correlation_id: metadata[:correlation_id] + reply_to = metadata[:reply_to] + + # if the RPC client uses explicit queue name for replies, it needs to be translated from STOMP + # semantics to AMQP. In this just removing the prefix /queue/ is sufficient + # See https://www.rabbitmq.com/stomp.html#d for details + reply_to = reply_to.sub(%r{^/queue/}, '') + + puts "Sent with routing key: #{reply_to}" + default_exchange.publish response_body, routing_key: reply_to, correlation_id: metadata[:correlation_id] end diff --git a/rpc/simple/rx-rpc-explicit-return-dest.html b/rpc/simple/rx-rpc-explicit-return-dest.html new file mode 100644 index 0000000..db5d9ab --- /dev/null +++ b/rpc/simple/rx-rpc-explicit-return-dest.html @@ -0,0 +1,150 @@ + + +
+ +