eventflow / EventFlow

Async/await first CQRS+ES and DDD framework for .NET
https://docs.geteventflow.net/
Other
2.33k stars 442 forks source link

Consume domain events from RabbitMQ #383

Closed rasmus closed 1 year ago

rasmus commented 6 years ago

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.

poumup commented 5 years ago

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 commented 5 years ago

Can someone give input about this issue ?

rasmus commented 5 years ago

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

rasmus commented 5 years ago

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

rasmus commented 5 years ago

@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.

poumup commented 5 years ago

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

rasmus commented 5 years ago

No worries, if you are up for it

poumup commented 5 years ago

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 commented 5 years ago

@rasmus what do you about my comment ?

rasmus commented 5 years ago

@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.

DureSameen commented 5 years ago

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.

poumup commented 5 years ago

So you have any branch , PR or sample ?

DureSameen commented 5 years ago

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.

rasmus commented 5 years ago

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

DureSameen commented 5 years ago

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

rasmus commented 5 years ago

@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.

DureSameen commented 5 years ago

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

rasmus commented 5 years ago

You'll need to create a pull request.

DureSameen commented 5 years ago

I am not allowed to push changes.

On Sat, Mar 30, 2019, 11:13 PM Rasmus Mikkelsen notifications@github.com 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 .

rasmus commented 5 years ago

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

github-actions[bot] commented 1 year ago

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] commented 1 year ago

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