0

I want to send the event to Microsoft Event-hub with Db transaction:

Explanation:

  1. User hit a endpoint of order creation.
  2. OrderService accept the order and put that order into the db.
  3. Now Order service want to send that orderId as event to another services using the Event-hub.

How can I achieve transactional behaviour for step 2 and 3?

I know these solutions:

  1. Outbox pattern: Where I put message in another table with order creation transaction. And there is one cron/scheduler, that takes the message from table and mark them delivered. and next time cron will take only not delivered messages.

  2. Use Database audit log and library that taken of this things. Library will bind the database table to Event-hub. Then on every update library will send that change to Event-hub.

I wanted to know is there any in-built transactional feature in Event-hub?

Or

Is there any better way to handle this thing?

Akashsingla19
  • 690
  • 2
  • 8
  • 18

1 Answers1

1

There is no concept of transactions within Event Hubs at present. I'm not sure, given the limited context that was shared, that Event Hubs is the best fit for your scenario. Azure Service Bus has transaction support and may be a more natural fit for your intended flow.

In this kind of distributed scenario, regardless of which message broker you decide on, I would advise embracing eventual consistency and considering a pattern similar to:

  • Your order creation endpoint receives a request

  • The order creation endpoint assigns a unique identifier for the request and emits the event to Event Hubs; if the send was successful it returns a 202 (Accepted) to the caller and a Retry-After header to indicate to the caller that they should wait for that period of time before checking the status of that order's creation.

  • Some process is responsible for reading events from the Event Hub and creating that order within the database. Depending on your ecosystem's tolerance, this may be a dedicated process or could be something like an Azure Function with an Event Hubs trigger.

  • Other event consumers interested in orders will also see the creation request and will call into your order service or database for the details using the unique identifier that as assigned by the order creation endpoint; this may or may not be the official order number within the system.

Jesse Squire
  • 6,107
  • 1
  • 27
  • 30