문제

The context

I have two components A & B, which communicate through events .

Components B is responsible for long running background processes and it listens to the following event:

startProcess(uniqueID)

Component A is sending the startProcess events.

The issue

I need the IDs sent by component A to be unique, cause elsewhere component B breaks.

Possible solutions

When component B receives an ID that has already been assigned to another a background job, does not accept it therefore rejects the initiation of a new background process.

The problem here is that component A does not know about the rejection, in contrast to a Http request response design, where the error is communicated through the response.

Question

Is there a better way to handle this, other than silently component B rejecting initiating a new process ? A definitely solution would be to forget about events and do this request/response way. But in general, how do event driven systems handle these kind of scenarios ?

Last

What I am doing at the moment is that component A bears the responsibility to send unique IDs. Is that the solution I am after?

도움이 되었습니까?

해결책

You are asking for a dead letter queue.

I am not sure what drives the uniqueness of the ID on component B. Are you trying to ensure one-time only delivery, or is that a requirement internal to component B? For the former, there are messaging frameworks which can deliver on that promise. For the latter, you can generate that unique ID internally.

다른 팁

my two cents based on a similar problem that I faced recently, Assuming that A and B do their best effort to do their task within their scope:

  • If the reliability of the whole system A-B-C depends only from the ID uniqueness, then A must be strengthen to create unique IDs and keep your current approach (blind delivery from A to B).
  • On the other hand, if the result of the process made by B matters (success/failure), A must take an orchestrator role, maybe using a queue in A to keep track of the IDs sent and take an action depending on the result that B will provide (if the result is an error, send notification, log it, try again x times, stop the sending of new IDs, etc., the best error handling that applies in your case).

I hope it helps, regards.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 softwareengineering.stackexchange
scroll top