EventFlow icon indicating copy to clipboard operation
EventFlow copied to clipboard

Consume domain events from RabbitMQ

Open rasmus opened this issue 8 years ago • 20 comments

As EventFlow is able to publish domain events to RabbitMQ, it should also be able to consume them if you want to link two bounded contexts using events.

rasmus avatar Sep 26 '17 17:09 rasmus

Hi @rasmus could you please give me input about your vision of implementation of this issue. I would like contribute because i need this feature. Thank

poumup avatar Aug 30 '18 00:08 poumup

Can someone give input about this issue ?

poumup avatar Sep 20 '18 22:09 poumup

Hi @poumup I started on the feature in PR #384, but didn't finish it yet. You could pick it up from there

rasmus avatar Sep 21 '18 10:09 rasmus

Ah, that PR is pretty empty. I'll see if I can give it some attention this weekend

rasmus avatar Sep 21 '18 10:09 rasmus

@poumup Don't I'll have a stable consumer ready this weekend. If you already have the code to consume messages from RabbitMQ in place, then EventFlow part is relatively simple.

This simple method handles the mapping of the RabbitMQ message to the domain events.

public IDomainEvent CreateDomainEvent(RabbitMqMessage rabbitMqMessage)
{
  var metadata = new Metadata(rabbitMqMessage.Headers);
  return _eventJsonSerializer.Deserialize(
    rabbitMqMessage.Message,
     metadata);
}

Then you basically need to do something similar to this:

RabbitMqMessage rabbitMqMessage = // have a look at how RabbitMqPublisher maps maps messages
var domainEvent = CreateDomainEvent(rabbitMqMessage);
await _domainEventPublisher.PublishAsync(
  new []{ domainEvent },
  cancellationToken)
  .ConfigureAwait(false);

I you have an example with a stable consumer that uses the "new" automatic recovery the RabbitMQ.Client recently added, then let me know.

rasmus avatar Sep 22 '18 18:09 rasmus

Hi apologize for the delay. Do you want me to continue the PR on the branch: rabbitmq-domain-event-consumer ?

poumup avatar Oct 09 '18 22:10 poumup

No worries, if you are up for it

rasmus avatar Oct 14 '18 10:10 rasmus

Hi,

Question. For consume domain event, imagine 2 microservices. The first one publish the domain event.

The second one whant to subscribe to the event, but don't know the aggregate class and the event class. So how to use IDomainEvent CreateDomainEvent(RabbitMqMessage rabbitMqMessage) ?

I suggest something like .AddRabbitMqSubscriber<IIntegrationMessage>("exchangeName", "QueueName", "RoutingKey")

where IIntegrationMessage is the rabbitmq serialized message

poumup avatar Oct 17 '18 00:10 poumup

@rasmus what do you about my comment ?

poumup avatar Dec 05 '18 21:12 poumup

@poumup makes sense. I haven't had much "EventFlow development time" in the evenings these last few weeks though. I expect I'll pick up soon though.

rasmus avatar Dec 11 '18 11:12 rasmus

Hello I have implemented rabbitmq subscriber that raise domainEventSubscriver successfully. But I am not sure where should I place my subscriber service startup. I need to start Subscriber service,integrated with eventflow.

DureSameen avatar Jan 30 '19 17:01 DureSameen

So you have any branch , PR or sample ?

poumup avatar Feb 05 '19 01:02 poumup

https://github.com/DureSameen/EventFlowWithElasticSearch. I have added a repository with two branches one WithRabbitMq and other is master. I have achieved same results in master which are also done in with rabbitMq branch.

The Idea is write at one end and read from other end. Master Branch: EventFlowApi : It is write api . Configured with EventFlow , ElasticSearch, EventStore and RabbitMq. It writes to all medium through read Models. EventFlowApi.Read: It is read api, it get ElasticSearch query handler and get the data from it.

WithRabbitMq Branch: EventFlowApi : It is write api . Configured with EventFlow , EventStore and RabbitMq. s. EventFlowApi.Read: It is read api, Configured with Eventflow and Elastic Search. It configured a RabbitMq subscriber at startup.which invoked Domain event subscribers when data is arrived. and insert the data in ElasticSearch.

DureSameen avatar Feb 05 '19 09:02 DureSameen

@DureSameen If you are interested you could add a link to your example from the read-me in the external examples section.

rasmus avatar Feb 12 '19 18:02 rasmus

you mean you add my example in read-me external example section.. yes Please...I will be honored..

DureSameen avatar Mar 19 '19 10:03 DureSameen

@DureSameen If developers are doing awesome stuff with EventFlow, writing example applications, writing articles, then I'm all for referencing the work from the read me file. If EventFlow is to have great future with a healthy community, then I cannot by any means do everything myself or even keeping it within the EventFlow GitHub org, nor should I. EventFlow will only grow if other developers contribute as no single developer (in my opinion) has the expertise to write an enterprise grade framework by themselves.

In short, just create the PR with the addition of the link to the external section, and I'll merge it in.

If you (or others) have any ideas on how to better involve the community, then please leave your comment in #602.

rasmus avatar Mar 19 '19 18:03 rasmus

I am receiving 403 error , when pushing changes in new branch.

DureSameen avatar Mar 29 '19 07:03 DureSameen

You'll need to create a pull request.

rasmus avatar Mar 30 '19 18:03 rasmus

I am not allowed to push changes.

On Sat, Mar 30, 2019, 11:13 PM Rasmus Mikkelsen [email protected] wrote:

You'll need to create a pull request.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/eventflow/EventFlow/issues/383#issuecomment-478273356, or mute the thread https://github.com/notifications/unsubscribe-auth/AHlk-5msIz5XbNyEo_IivQJAOwUbf3hpks5vb6lYgaJpZM4PkotF .

DureSameen avatar Mar 30 '19 18:03 DureSameen

No, not to the EventFlow repository, only a few members have that.

You'll need to fork the repo or do it directly in the UI. GitHub has some excellent documentation on how to do it. https://help.github.com/en/articles/creating-a-pull-request

rasmus avatar Mar 30 '19 18:03 rasmus

Hello there!

We hope you are doing well. We noticed that this issue has not seen any activity in the past 90 days. We consider this issue to be stale and will be closing it within the next seven days.

If you still require assistance with this issue, please feel free to reopen it or create a new issue.

Thank you for your understanding and cooperation.

Best regards, EventFlow

github-actions[bot] avatar Apr 08 '23 13:04 github-actions[bot]

Hello there!

This issue has been closed due to inactivity for seven days. If you believe this issue still needs attention, please feel free to open a new issue or comment on this one to request its reopening.

Thank you for your contribution to this repository.

Best regards, EventFlow

github-actions[bot] avatar Apr 16 '23 09:04 github-actions[bot]