Azure service bus - how to add metadata to the message

后端 未结 1 1485
自闭症患者
自闭症患者 2021-01-24 17:30

I am using .net core web app as the publisher and .net core console app as subscriber. I am able to successfully pass messages between these two systems using Managed Identitie

相关标签:
1条回答
  • 2021-01-24 18:00

    Message object has a property called UserProperties that can be used to set custom metadata for that message.

    Something like:

    string data = JsonConvert.SerializeObject(payloadEvents);
    Message message = new Message(Encoding.UTF8.GetBytes(data));
    message.UserProperties.Add("key1", "value1");
    message.UserProperties.Add("key2", "value2");
    
    var tokenProvider = TokenProvider.CreateManagedIdentityTokenProvider();
    
    TopicClient sendClient = new TopicClient(_serviceBusNamespace, _topicName, tokenProvider, retryPolicy: null);
    
    await sendClient.SendAsync(message);
    
    0 讨论(0)
提交回复
热议问题