question

HassanAbbasi-1538 avatar image
0 Votes"
HassanAbbasi-1538 asked MayankBargali-MSFT edited

Is there anyway to get notified when new topic is added in azure service bus?

Basically I need to do some custom work whenever any new topic is added into the service bus, I checked the documentation of event grids but there is not event type which raises this event, I appreciate if anyone can help on this?

azure-event-grid
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

1 Answer

MayankBargali-MSFT avatar image
0 Votes"
MayankBargali-MSFT answered MayankBargali-MSFT edited

@HassanAbbasi-1538 As you have mentioned there are no predefine events in eventgrid for service bus that can help you in this case. Neither there is any alert that can be set on the service bus resource that can help you. There are multiple ways of creating topic either using azure portal, service bus REST API, SDK, etc.

Therefore in your scenario, if the topic can be created in anyways then the best way will be to write your custom logic to get all the topics in the service bus and check the created date of that topic and accordingly perform the logic once you have verified that the topic is recently created. According to your business requirement, you need to run this logic per hr/min/day, etc.

But if the topic is only created using azure portal, Azure management APIs (not using service bus APIs) etc. then you can create the event grid at the resource group level. Check for 'Microsoft.Resources.ResourceWriteSuccess' events and apply different filter condition like subject contains "/subscriptions/{yoursubscriptionID}/resourceGroups/{resourcegroupname}/providers/Microsoft.ServiceBus/namespaces/{servicebusname}/topics/" so only the specific events are send to the configured endpoint. At the configured endpoint you need to write your own logic to verify the data object and check the action Microsoft.ServiceBus/namespaces/topics/write and might need to check other fields of eventgrid response so you can only process the event that you are interested in. If you are going with this logic make sure to test different use cases to figure out only created topic events.


"data": {
"authorization": {
"scope": "/subscriptions/subscriptionID/resourceGroups/{resourcegroupname}/providers/Microsoft.ServiceBus/namespaces/{servicebusname}/topics/{yourtopicname}",
"action": "Microsoft.ServiceBus/namespaces/topics/write",
"evidence": {
"role": "Subscription Admin"
}

Unfortunately, as there is no out-of-box feature that can help you in your case and you need to write your own logic to figure out when the topic is created.

· 1
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

Thanks for the detailed answer, it is really helpful.

1 Vote 1 ·