Poll database table and create events

This article mentions a solution where one or more database triggers insert events into an “EVENTS” table, which is polled by a separate process that publishes the events.

Is there an inbuilt functionality in NServiceBus for such polling? Or should I generate commands which does the polling at an interval?

Hi!

What you mention can be achieved with our SqlServer transport option. This sample shows how triggers can be used to emit events based on changes in the database.

Was this what you had in mind?

Cheers,

Andreas

I’m trying to avoid such database coupling cos it would make it more difficult to change the transport if and when needed.

I can see that NServiceBus polls the database tables to handle commands etc but I guess it just internal handling of SQL Transport.

Basically what I would like to do is poll a db table “Events” and publish events when new rows are created there.

I’m trying to avoid such database coupling cos it would make it more difficult to change the transport if and when needed.

In that case just creating a thread in your endpoint that just polls the database would be the simplest way to do this.

Should you need to do the polling on some more complex schedule you could look at using a scheduler

Or should I generate commands which does the polling at an interval?

I would recommend against using messages for this since if there is lots of events to publish, eg. after the poller being down for some time, publishing might take a long time and cause you to run into the transaction timeout of the transport that you are using. A custom thread like mentioned above would not have this issue.

For completeness, but most likely overkill in your case, you could use SqlTransport as originally
proposed and combine it with the NServiceBus Router • NServiceBus.Router • Particular Docs to decouble the rest of your system from the SqlTransport.

Hope this helps!