Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Windows Azure Service Bus - BrokeredMessage.Properties with Enum Value

I am trying to add a custom property to the BrokeredMessage.Properties collection before sending it to the Azure Service Bus. The custom property type is an enum:

[Serializable, DataContract]
public enum FooBar
{
    [EnumMember]
    Foo = 0,
    [EnumMember]
    Bar = 1
}

I have also tried numerous combinations of the Attributes, and a version with no Attributes.

This is the code which adds the property and sends the message:

var brokeredMessage = new BrokeredMessage(new MessageObject(){ //etc });
brokeredMessage.Properties.Add("FooBar", FooBar.Foo);
queueClient.Send(brokeredMessage);

The following error is returned when attempting to send the message:

System.Runtime.Serialization.SerializationException : Serialization operation failed due to unsupported type Namespace.FooBar.

I've tried to track down some more detailed documentation on the BrokeredMessage.Properties limitations (if any), and can't find anything which specifies that only primitive types can be used.

Any ideas as to why this doesn't work?

Edit:

Should have said I am using V2.1.0.0 of Microsoft.ServiceBus.

like image 757
GaryJL Avatar asked May 31 '13 13:05

GaryJL


People also ask

How do I read messages from Azure Service Bus queue?

Overview of application Create Azure Service Bus Queue using Azure Portal. Create HTTP trigger Azure Function to send the message into Queue. Create a Service Bus Queue trigger Azure function to read a message from Queue.

Where does Azure Service Bus store data?

Azure Service Bus premium tier stores metadata and data in regions that you select. When geo-disaster recovery is set up for an Azure Service Bus premium namespace, the metadata is copied over to the secondary region that you select.


1 Answers

Shortly, you can use only simple types like string, integers.

For your case, you can try two ways

  1. brokeredMessage.Properties.Add("FooBar", (int)FooBar.Foo);
  2. brokeredMessage.Properties.Add("FooBar", FooBar.Foo.ToString());

Choose by you self, which one is better for you.

like image 185
user2399170 Avatar answered Oct 21 '22 20:10

user2399170