Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

AMQP Rabbit #235

Open
avinashs433 opened this issue Aug 17, 2022 · 6 comments
Open

AMQP Rabbit #235

avinashs433 opened this issue Aug 17, 2022 · 6 comments
Assignees
Labels
question Further information is requested

Comments

@avinashs433
Copy link

avinashs433 commented Aug 17, 2022

Hi,

Can you please provide an example/documentation how to dispatch and consume a message to and from rabbitMQ using ToAmqpMessage() ?

 var formatter = new JsonEventFormatter();

 var message = cloudEvent.ToAmqpMessage(ContentMode.Binary, formatter);

 var encoded = message.Encode();

//This message is then published to rabbit

Consumer

// Reading the message
Task<bool> MessageProcessor(BasicDeliverEventArgs eventArgs)
{
            var formatter = new JsonEventFormatter();
            var byteBuffer = new ByteBuffer(eventArgs.Body.ToArray(), 0, eventArgs.Body.Length, eventArgs.Body.Length);
            var message = Message.Decode(byteBuffer);
            var cloudEvent = message.ToCloudEvent(formatter);

// also tried
           var byteBuffer = JsonSerializer.Deserialize<ByteBuffer>(eventArgs.Body.ToArray());
            var message1 = Message.Decode(byteBuffer);
}
@jskeet
Copy link
Contributor

jskeet commented Aug 17, 2022

I've never used Rabbit - it would really help if you'd say what happens with the code that you've already tried. Does it throw an exception? What happens?

@jskeet jskeet self-assigned this Aug 17, 2022
@jskeet jskeet added the question Further information is requested label Aug 17, 2022
@avinashs433
Copy link
Author

avinashs433 commented Aug 17, 2022

It throws an exception
"Structured mode content does not represent a CloudEvent" on the consumer.

Not sure if I an sending it correctly across to rabbit.
Was referring to this test

                CloudEvent cloudEvent = new CloudEvent(CloudEventsSpecVersion.Default)
                {
                    Id = Guid.NewGuid().ToString(),
                    Type = "test.game.updated",
                    Time = DateTime.UtcNow,
                    Source = new Uri($"/Games/{notification.GameId}"),
                    DataContentType = "application/cloudevents+json",
                    Data = notification,
                };

@jskeet
Copy link
Contributor

jskeet commented Aug 17, 2022

Not sure if I an sending it correctly across to rabbit.

As I said, I've never used Rabbit, so I don't know on that front.

Are you able to decode the result of calling Encode, i.e. getting everything to work from a CloudEvent to an encoded message and back again without actually sending it to Rabbit?

Fundamentally you're encoding this using binary content mode, so I wouldn't expect it to try to deserialize using structured content mode, unless you're setting a content type somewhere that makes it look like it's structured.

@avinashs433
Copy link
Author

avinashs433 commented Aug 17, 2022 via email

@jskeet
Copy link
Contributor

jskeet commented Aug 17, 2022

Yeah I am able to encode and decode on the publisher side.

In that case it's presumably something to do with how you're sending and receiving the message - which I won't be able to help with, I'm afraid (and which we can't even see completely in terms of the code you've provided).

I notice that you're only using the body of BasicDeliverEventArgs - I don't know whether that's the problem, but it's worth looking into. Fundamentally if the receiving side doesn't get back the same data that the publisher side sent, that's going to be a problem - you might want to ask in a Rabbit-specific repo/forum.

@avinashs433
Copy link
Author

avinashs433 commented Aug 17, 2022 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants