Topic-Subscription
I would like to extend the answer by @arnumprabhu. If you want to use different message types then you should be looking for Topic-Subscription model. This way your publish the message at topic and services that are subscribed to it can get the message. Each topic can have many subscriptions and each subscription can listen to only particular type of messages or all them. e.g. You publish 3 messages. BookingConfirmed, PaymentProcessed, OrderDelivered. You have 3 subscriptions which can listen to any of the above messages or all of them . Say your subscription (Say name of subscription is Tracking) decides to listen to 2 messages BookingConfirmed , PaymentProcessed. When ever the message is published to topic , your subscription gets copy of these messages
Azure function
Your azure function can subscribe to the subscription (Tracking) and only listen to the messages arrived on this subscription. On a very high level it could look something like this.
[FunctionName("myfunction")]
public static async void Run([ServiceBusTrigger("topicName", "Subscriptionname", Connection = "ServiceBus")]Message serviceBusMessage, ILogger log)
{
EventStore eS = new EventStore();
await eS.UpdateData(serviceBusMessage);
// log.LogInformation($"C# ServiceBus topic trigger function processed message: {mySbMsg}");
}
public class EventStore
{
public async Task UpdateData(Message msg)
{
try
{
if (msg.Label == "BookingAdd")
{
BookingAddIntegrationEvent eventMsg = JsonConvert.DeserializeObject<BookingAddIntegrationEvent>(Encoding.UTF8.GetString(msg.Body));
string messageType = "BookingCreated";
BookingCreated bookingCreated = new
BookingCreated(eventMsg.BookingId, string.Empty, eventMsg.Id
, messageType, eventMsg.CreationDate, eventMsg.Origin, eventMsg.Destination);
bookingId = eventMsg.BookingId;
tracking.BookingAdd(bookingCreated);
}
else if (msg.Label == "OrderPicked")
{
OrderPickedIntegrationEvent eventMsg = JsonConvert.DeserializeObject<OrderPickedIntegrationEvent>(Encoding.UTF8.GetString(msg.Body));
string messageType = "OrderPicked";
OrderPicked orderPicked = new
OrderPicked(eventMsg.BookingId, eventMsg.Description, eventMsg.Id
, messageType, eventMsg.CreationDate);
bookingId = eventMsg.BookingId;
tracking.OrderPicked(orderPicked);
}
}
catch (Exception ex)
{
throw ex;
}
}
}
}