My client or my server seems not to work
Here is my server , a simple code doing a find against mongodb
class Mongo(object):
name = "mongo"
@rpc
def findStudent(self, username):
client =
MongoClient('mongodb://admin:XXXX@localhost:2707?authSource=admin')
db = client.local
col = db.school
result = col.find_one({'username': username})
return ('{ username: "' + result['username'] + '", age: "' +
str(result['age']) + '"}')
my client Java call routing kay : mongo.findStudent
Arguments : "{'args': ['lbois']}"
And the returned response is an echo of the call:
{"content":"Returned message from service: {'args': ['lbois']} !"}
I'm waiting about the database content and not the echo of my call
I think that doesn't work
Laurent
···
Le jeudi 15 mars 2018 10:56:58 UTC+1, Matt Yule-Bennett a écrit :
Congratulations, your client is working.
On Thursday, March 15, 2018 at 7:11:35 AM UTC, Laurent Bois > M/45/174/90/CF-L1 wrote:
Trying to play with payload.
I have a consumer ack alreadymy service is now
class Crawler(object):
name = "crawler"
@rpc
def scrapit(self, a, b, c='C', d='D'):
return (a,b,c,d)and in my Java Client
channel.basicPublish( EXCHANGE_NAME, "crawler.scrapit", props, "{'args':
['hello', 'world', 'kwargs': {'c':'foo', 'd':'bar'}]}".getBytes("UTF-8"
));Now i got a returned message like this
"Returned message from service: {'args': ['hello', 'world', 'kwargs': {'c':'foo', 'd':'bar'}]} !"}
Is it normal? Or is it just an echo
This is what you've asked your service to return. The RPC entrypoint will
serialize (if it can) whatever is returned from the decorated method and
return that to the client.Laurent
Le mercredi 14 mars 2018 17:23:55 UTC+1, Matt Yule-Bennett a écrit :
The *routing_key* needs to be "<service-name>.<method-name>".
The *payload* needs to be a serialized dict in the form: {"args":
<positional-arguments>, "kwargs": <keyword-arguments>}For example, if I had a service:
class Service:
name = "service"@rpc
def method(self, a, b, c="C", d="D"):
print(a, b, c, d)And I published a message to the RPC exchange with:
*routing_key*: service.method
*payload*: {'args': ['hello', 'world', 'kwargs': {'c':'foo',
'd':'bar'}]}The service would print:
hello world foo bar
On Tuesday, March 13, 2018 at 3:30:46 PM UTC, Laurent Bois >>> M/45/174/90/CF-L1 wrote:
Hi folks
How can you translate a payload : service-name-method_name in JSON with
{args: , kwargs: } notation?Thanks
Laurent
Le mardi 13 mars 2018 16:30:23 UTC+1, lauren...@gmail.com a écrit :
Thanks for this great explanation
I think the problem can come from the serialization of the payload in
Java. In my code i just do a byte conversion from string (service.method)In my last tries i sent the payload to the echange, with a reply queue
(bit not named as you say)I'm going to try what you wrote and come back
Thanks
Le lundi 12 mars 2018 10:41:31 UTC+1, Matt Yule-Bennett a écrit :
I took a closer look at this and found more problems. I don't have a
complete copy of your client so let me just explain in English how the RPC
flow works.* The listening service will have declared the "nameko-rpc" exchange,
and a queue called "rpc-<service-name>", bound to it with the routing key
"<service-name>.*" (it's a topic exchange)
* You must declare an RPC reply queue. The queue name can be anything
but the nameko Python client names them "rpc.reply-<service-name>-<uuid>".
It must be bound to the "nameko-rpc" exchange with a unique name; the
Python client uses a uuid.
* To make a call, you publish a message to the "nameko-rpc" exchange,
with "<service-name>.<method-name>" as the routing key. The payload must be
a serialised dict containing the key "args" and "kwargs", with the values
being the parameters for the method call. You must specify a "reply_to"
header with the routing key you've used to bind the reply queue to the RPC
exchange. You should also specify a "correlation_id" header so your client
can issue multiple concurrent requests and match the replies back up again.
You also need to specify content-type and encoding headers so the service
knows how to deserialize the incoming data. By default the listening
service will be expecting JSON.
* The request message will be routed to the listening service's
queue, consumed, processed and ack'd. The service will then reply by
publishing to the RPC exchange using the "reply_to" as the routing key and
including the "correlation_id header from the request message.
* The response message will be routed to the reply queue. Your client
should consume it and use the correlation id to match it up with a pending
request.Looking at your first post, the client is not publishing the request
message correctly. It's sending it directly to the service queue via the
default exchange, without the correct routing key. Your service is probably
consuming the message and replying with a MethodNotFound message, which was
being lost because your reply queue wasn't bound correctly either. Your
payload also isn't correct in the first version. It should be (assuming
JSON serialization) '{"args": , "kwargs": }'On Monday, March 5, 2018 at 8:27:32 AM UTC, lauren...@gmail.com >>>>>> wrote:
I changed my client code :
First i declare the exchange:
private static final String EXCHANGE_NAME = "nameko-rpc";
Then after further tries i declare the exchange :
Channel channel = connection.createChannel();
channel.exchangeDeclare(EXCHANGE_NAME, "topic", true);
Finally i publish my message directly to the exchange and not the requestQueueName ...found the code on RabbitMQ for Publish/Subscribe , section EmitLog client RabbitMQ tutorial - Publish/Subscribe — RabbitMQ
channel.basicPublish(EXCHANGE_NAME, "", props, message.getBytes());
The message is a string to the nameko service.methode_name as it : crawler.scrapit()
I see the message in the RabbitMQ console management, no more the ack .
I have a log in my nameko service but nothing prints in the Terminal... as if the service is not hit
Le dimanche 4 mars 2018 22:54:06 UTC+1, Matt Yule-Bennett a écrit :
On Sunday, March 4, 2018 at 8:30:23 PM UTC, lauren...@gmail.com >>>>>>>> wrote:
Thanks.
In my client, after
channel = connection.createChannel();
replyQueueName = channel.queueDeclare().getQueue();
I've added this line
channel.queueBind( replyQueueName , "nameko-rpc", "reply_to");
Have you bound your reply queue with the *literal value*
"reply_to"? That won't work. It needs to be the value that you've specified
in the "reply to" header in your request message. In your case that's
replyQueueName.But same results... the client is stil blocking
<snip>
So the queue would be 'rpc-crawler' right?
That is correct, yes. If it wasn't correct you would not see the
request message being ack'd by your service.Laurent
Le dimanche 4 mars 2018 20:57:35 UTC+1, Matt Yule-Bennett a écrit :
The RPC reply queue must be bound to the `nameko-rpc` exchange.
The reply message is published to that exchange with the 'reply_to' as the
routing key; if you haven't bound the reply queue to the correct exchange,
the reply message will be discarded by the broker as not matching any
routes.Correlation ID has nothing to do with routing messages. It's only
used to match replies up with requests so a client can have multiple
requests in flight at the same time.On Sunday, March 4, 2018 at 6:37:01 PM UTC, lauren...@gmail.com >>>>>>>>>> wrote:
The problem is before the correlationId.
In the Java source code that is handleDelivery which blocks
Le dimanche 4 mars 2018 19:25:01 UTC+1, lauren...@gmail.com a
écrit :Yes but in my Java client i manage the replyQueue
I Use correlationId.
I started from the Java code in RabbitMQ RPC/Java/CorrelationId
section
https://github.com/rabbitmq/rabbitmq-tutorials/blob/master/java/RPCClient.javaIn my RabbitMQ management page i see the message sent from
client , the Publisher confirm, and the ack nowAs you say maybe it's a problem with the reply queue, and error
in my client
LaurentLe dimanche 4 mars 2018 12:48:11 UTC+1, Matt Yule-Bennett a
écrit :An ack for the request message means that it was received and
processed without any error, including sending the reply.The reply message is almost certainly being published but not
routed to the appropriate reply queue. Looking at your code... is your
reply queue bound to the RPC exchange? If not, that's your problem.On Sunday, March 4, 2018 at 11:43:49 AM UTC, >>>>>>>>>>>>> lauren...@gmail.com wrote:
I only see a ack on the RabbitMQ management page... i see my
message sent
I do not see answer in the reply queue
I think the entrypoint is hit because there is an ack, but i
do not understand why the replied message is not sent