Azure/azure-functions-rabbitmq-extension

RabbitMQAsyncCollector.AddAsync only adds to publish the body, not the properties

michaeltg17 opened this issue · 2 comments

Hi.

The parameter "message" in method "RabbitMQAsyncCollector.AddAsync" recieves the full BasicDeliverEventArgs object as ReadOnlyMemory, converted from the class PocoToBytesConverter. In the message, we have the BasicProperties, but this method is adding all the content of the message into the body parameter of the publlish method and setting the BasicProperties to null.

This causes the message to be published without the basic properties (although they are in the body section).

image

@michaeltg17, are you trying to set output binding parameter like below:

public static void UserFunction(
    [QueueTrigger("queue-name")] string message, // Could be any trigger.
    [RabbitMQ(QueueName = "queue")] IAsyncCollector<BasicDeliverEventArgs> outMessages)

RabbitMQ extension does not have a special handling for BasicDeliverEventArgs for output binding so it treats it as a regular POCO class, converts it to JSON string and passes it as body to the output RabbitMQ queue. It does have special handling for type BasicDeliverEventArgs in trigger binding.

I can be wrong, but I think the reason for this is BasicDeliverEventArgs is only used for accepting messages from queue, not for sending messages back. For that user needs to make direct request to BasicPublishBatch.Add method. Let me know if you can find an example that contradicts this.

If your function looks similar to the example above, you can change it to below to get handle of the RabbitMQ channel and publish messages on it directly passing in the properties:

public static void UserFunction(
    [QueueTrigger("queue-name")] string message, // Could be any trigger.
    [RabbitMQ(QueueName = "queue")] IModel channel)
{
    channel.BasicPublish(exchange: string.Empty, routingKey: <queue-name>, basicProperties: <your-properties>, body: body);
}

This issue has been automatically marked as stale because it has been marked as requiring author feedback but has not had any activity for 4 days. It will be closed if no further activity occurs within 3 days of this comment.