Today I will continue discussion about Service Bus Queue with X topics.
Let’s assume that we have messages that we need to deliver on the queue only on a specific type. How should we do this? First solution that can come in our mind is to create a service, something like a schedule that will add the message to the queue only on a given time. This is a possible solution, but we need to develop a service, we need to host this. All of this means money and resources.
Another simple solution is to use the scheduled functionality that is offered by the Service Bus from Windows Azure. Any message that is added to the Service Bus Queue can be scheduled. Each message that is created can have the property “ScheduledEnqueueTimeUtc” set to a given value. When this value is not set the message is automatically added and available to the queue. When we set this value, the message will enqueued to the queue only at the specific time.
From the code, the only thing that we need to do is to set this property. Is not need to specify something when we send this message or something similar.
Let’s assume that we have messages that we need to deliver on the queue only on a specific type. How should we do this? First solution that can come in our mind is to create a service, something like a schedule that will add the message to the queue only on a given time. This is a possible solution, but we need to develop a service, we need to host this. All of this means money and resources.
Another simple solution is to use the scheduled functionality that is offered by the Service Bus from Windows Azure. Any message that is added to the Service Bus Queue can be scheduled. Each message that is created can have the property “ScheduledEnqueueTimeUtc” set to a given value. When this value is not set the message is automatically added and available to the queue. When we set this value, the message will enqueued to the queue only at the specific time.
From the code, the only thing that we need to do is to set this property. Is not need to specify something when we send this message or something similar.
QueueClient qc =
QueueClient.CreateFromConnectionString(
myFooConnectionString, "FooQueue");
BrokeredMessage message = new BrokeredMessage();
message.Properties["Name"] = "Radu Vunvulea";
// The message will be enqueue in 1 hour from the current time.
message.ScheduledEnqueueTimeUtc = DateTime.UtcNow.Add( new TimeSpan(0,1,0,0));
qc.Send(message);
As you can see is quite simple to do something like this. We don’t have to reinvent the wheel. This functionality is already built in in Service Bus. Next we will talk how we can integrate WCF to Service Bus.
Comments
Post a Comment