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

Headers? #197

Closed
magnayn opened this issue Jun 13, 2022 · 3 comments
Closed

Headers? #197

magnayn opened this issue Jun 13, 2022 · 3 comments

Comments

@magnayn
Copy link

magnayn commented Jun 13, 2022

With Azure, I can use IAsyncCollector and ServiceBusReceivedMessage[] in my functions in order to get access to the message headers.

This is important to extract metadata.

How is this achieved with the RabbitMQ binding?

@JatinSanghvi
Copy link
Contributor

Can you try this? Bind the RabbitMQTrigger to BasicDeliverEventArgs type as in here. Then look for headers under args.BasicProperties.Headers.

@magnayn
Copy link
Author

magnayn commented Jun 14, 2022 via email

@JatinSanghvi
Copy link
Contributor

Hi, I had a suggestion but did not get time try it out myself earlier. Here is what is possible:

public static void BindToChannel(
    [TimerTrigger("01:00", RunOnStartup = true)] TimerInfo timer,
    [RabbitMQ(ConnectionStringSetting = "rabbitMQ")] IModel channel)
{
    channel.QueueDeclare(queue: "hello", false, false, false, null);

    IBasicProperties properties = channel.CreateBasicProperties();
    properties.Headers = new Dictionary<string, object> { ["headerName"] = "headerValue" };
    byte[] body = Encoding.UTF8.GetBytes("Hello World!");
    channel.BasicPublish(exchange: string.Empty, routingKey: "hello", properties, body);
}

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

No branches or pull requests

2 participants