Azure / azure-service-bus-dotnet

☁️ .NET Standard client library for Azure Service Bus
https://azure.microsoft.com/services/service-bus
Other
235 stars 120 forks source link

Expose different AMQP messages (e.g., AMQPValue message) #498

Open roberino opened 6 years ago

roberino commented 6 years ago

Actual Behavior

  1. We are sending messages using mule-module-servicebus 1.3.1 and the AMQ protocol
  2. We are receiving the message using the new service bus client for dotnet (v 3.0.0)
  3. The Body property of the received message is null

Expected Behavior

  1. The Body property of the received message should not be null
  2. The behaviour of a message should be consistent regardless of the transport protocol

Versions

nemakam commented 6 years ago

There are multiple options to format that body in AMQP protocol including AmqpValue , or Data body. We use Data body within azure SDKs. It depends on how MuleSoft encodes the data while sending to service bus. Do you know if it is wrapped as AmqpValue or Data body within mulesoft connector? Also, could you share a sample repro?

roberino commented 6 years ago

Hi...I'm afraid I don't have further details regarding the mulesoft connector as a third-party has implemented this but...

...we've managed to work around this by using the GetBody Interop function as implemented in the example code below. What we're trying to ensure is that the behaviour is consistent regardless of the protocol as we have numerous message publishers and message subscribers.

Looking at the implementation of GetBody, it would seem in our case that the body of the message is being sent as an AmqpValue and not in the Data section (as our third party is sending the body as a JSON encoded string).

Currently, the dotnet service bus library does not expose the internal AMQP object model and the only way I can see to get the AmqpValue is via the MessageInteropExtensions which seems like it's intended for Data Contract serialized messages.

Are there plans to expose some of this in future?

Example workaround:


internal static byte[] GetBodyBytes(this Message message)
        {
            if (message.Body != null) return message.Body;

            var msg = message.GetBody<object>()?.ToString();

            return msg == null ? null : Encoding.UTF8.GetBytes(msg);
        }
nemakam commented 6 years ago

Yes. We do want to expose bare AmqpMessage to the user just to handle scenario like yours. But we haven't got to it yet, and don't have a proper timeline for that feature either.