New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature Message Queue Integration #2264

Open
wants to merge 11 commits into
base: master
from

Conversation

Projects
None yet
7 participants
@personball

personball commented Jun 28, 2017

In this PR, I submit a solution about Message Queue Integration.

Change List:

  1. In project Abp, Add namespace Abp.MqMessages with interface IMqMessagePublisher and class NullMqMessagePublisher
  2. Add Projects:
    Abp.MqMessages
    Abp.MqMessages.Rebus
    Abp.MqMessages.RebusRabbitMqPublisher
    Abp.MqMessages.RebusRabbitMqConsumer
  3. Add mq-messages-sample in test folder with 3 sample projects.

Usage:

1. Message Definition in Sample.MqMessages

namespace Sample.MqMessages
{
    /// <summary>
    /// Custom MqMessage Definition. No depends on any framework,this class library can be shared as nuget pkg.
    /// </summary>
    public class TestMqMessage
    {
        public string Name { get; set; }
        public string Value { get; set; }
        public DateTime Time { get; set; }
    }
}

2. PublisherModule

2.1 Configuration

namespace Sample
{
    [DependsOn(typeof(RebusRabbitMqPublisherModule))]
    public class SampleRebusRabbitMqPublisherModule : AbpModule
    {
        public override void PreInitialize()
        {
            Configuration.Modules.UseRebusRabbitMqPublisher()
                .UseLogging(c => c.NLog())
                .ConnectionTo("amqp://dev:dev@rabbitmq.local.cn/dev_host");

            Configuration.BackgroundJobs.IsJobExecutionEnabled = true;
        }

        public override void Initialize()
        {
            IocManager.RegisterAssemblyByConvention(Assembly.GetExecutingAssembly());
        }

        public override void PostInitialize()
        {
            Abp.Dependency.IocManager.Instance.IocContainer.AddFacility<LoggingFacility>(f => f.UseNLog().WithConfig("nlog.config"));

            var workManager = IocManager.Resolve<IBackgroundWorkerManager>();
            workManager.Add(IocManager.Resolve<TestWorker>());// to send TestMqMessage every 3 seconds
        }
    }
}

2.2 In TestWork

namespace Sample.BackgroundWorks
{
    public class TestWorker : PeriodicBackgroundWorkerBase, ISingletonDependency
    {
        private readonly IMqMessagePublisher _publisher;

        public TestWorker(AbpTimer timer, IMqMessagePublisher publisher)
            : base(timer)
        {
            _publisher = publisher;
            Timer.Period = 3000;//3 seconds
            Timer.RunOnStart = true;
        }

        protected override void DoWork()
        {
            Logger.Info($"TestWork Done! Time:{DateTime.Now}");
            _publisher.Publish(new TestMqMessage
            {
                Name = "TestWork",
                Value = "BlaBlaBlaBlaBlaBla",
                Time = DateTime.Now
            });
        }
    }
}

3. ConsumerModule

3.1 Configuation

namespace Sample
{
    [DependsOn(typeof(RebusRabbitMqConsumerModule))]
    public class SampleRebusRabbitMqConsumerModule : AbpModule
    {
        public override void PreInitialize()
        {
            Configuration.Modules.UseRebusRabbitMqConsumer()
                .UseLogging(c => c.NLog())
                .ConnectTo("amqp://dev:dev@rabbitmq.local.cn/dev_host")
                .UseQueue(Assembly.GetExecutingAssembly().GetName().Name)
                .RegisterHandlerInAssemblys(Assembly.GetExecutingAssembly());//register assembly whitch has rebus handlers
        }

        public override void Initialize()
        {
            base.Initialize();
        }

        public override void PostInitialize()
        {
            Abp.Dependency.IocManager.Instance.IocContainer.AddFacility<LoggingFacility>(f => f.UseNLog().WithConfig("nlog.config"));
        }
    }
}

3.2 Rebus Handler in Consumer

namespace Sample.Handlers
{
    public class TestHandler : IHandleMessages<TestMqMessage>
    {
        public ILogger Logger { get; set; }
        public IMqMessagePublisher Publisher { get; set; }
        public TestHandler()
        {
            Publisher = NullMqMessagePublisher.Instance;
        }

        public async Task Handle(TestMqMessage message)
        {
            var msg = $"{Logger.GetType()}:{message.Name},{message.Value},{message.Time}";
            Logger.Debug(msg);
            await Publisher.PublishAsync(msg);//send it again!
        }
    }
}

If you want to run this sample, you need an instance of rabbitmq and set ConnectionString like amqp://dev:dev@rabbitmq.local.cn/dev_host.

@personball personball changed the title from Feature mq messages to Feature Message Queue Integration Jun 28, 2017

@hikalkan hikalkan self-requested a review Jun 28, 2017

@hikalkan hikalkan added the feature label Jun 28, 2017

@hikalkan hikalkan added this to the v2.2 milestone Jun 28, 2017

@hikalkan

This comment has been minimized.

Show comment
Hide comment
@hikalkan

hikalkan Jun 28, 2017

Member

Thank you for your contribution. I will try to review this in next version.

Member

hikalkan commented Jun 28, 2017

Thank you for your contribution. I will try to review this in next version.

@hikalkan hikalkan modified the milestones: v2.3, v2.2 Jul 17, 2017

@hikalkan hikalkan modified the milestones: v2.3, v2.4 Jul 30, 2017

@hikalkan hikalkan modified the milestones: v2.4, v2.5 Aug 12, 2017

@hikalkan hikalkan modified the milestones: v3.1, Backlog Oct 3, 2017

@AlexSenchenko

This comment has been minimized.

Show comment
Hide comment
@AlexSenchenko

AlexSenchenko Oct 3, 2017

Hi @personball
Are you using it already (Win/linx)? Is it mature enough?

AlexSenchenko commented Oct 3, 2017

Hi @personball
Are you using it already (Win/linx)? Is it mature enough?

@personball

This comment has been minimized.

Show comment
Hide comment
@personball

personball Oct 9, 2017

@AlexSenchenko Yes, Windows work fine, but linux not tested yet.

For some dependency (Rebus) not resolved in dotnet standard 2.0. I can't say it works fine on linux.

personball commented Oct 9, 2017

@AlexSenchenko Yes, Windows work fine, but linux not tested yet.

For some dependency (Rebus) not resolved in dotnet standard 2.0. I can't say it works fine on linux.

@lataing

This comment has been minimized.

Show comment
Hide comment
@lataing

lataing Jan 27, 2018

Why stop updating this feature? Is the technical problem? Personally, I think this is an important function.

lataing commented Jan 27, 2018

Why stop updating this feature? Is the technical problem? Personally, I think this is an important function.

@ismcagdas

This comment has been minimized.

Show comment
Hide comment
@ismcagdas

ismcagdas Jan 27, 2018

Member

@hikalkan what do you think ? Can we add it to v3.5 ?

Member

ismcagdas commented Jan 27, 2018

@hikalkan what do you think ? Can we add it to v3.5 ?

@lataing

This comment has been minimized.

Show comment
Hide comment
@lataing

lataing Jan 27, 2018

Maybe that's a good choice.
https://github.com/tangxuehua/equeue
a distributed mq written by c#.
He does not need to install third party software.

lataing commented Jan 27, 2018

Maybe that's a good choice.
https://github.com/tangxuehua/equeue
a distributed mq written by c#.
He does not need to install third party software.

@natiki

This comment has been minimized.

Show comment
Hide comment
@natiki

natiki Jan 29, 2018

Contributor

@lataing I would definitely like to see some more documentation before considering equeue.

Contributor

natiki commented Jan 29, 2018

@lataing I would definitely like to see some more documentation before considering equeue.

@personball

This comment has been minimized.

Show comment
Hide comment
@personball

personball Feb 24, 2018

@lataing As now, you can use this feature through my repo:https://github.com/personball/abplus. But it's not tracking latest version of ABP yet, you can fork the repo and work it out with no limitations.

personball commented Feb 24, 2018

@lataing As now, you can use this feature through my repo:https://github.com/personball/abplus. But it's not tracking latest version of ABP yet, you can fork the repo and work it out with no limitations.

@hitaspdotnet

This comment has been minimized.

Show comment
Hide comment
@hitaspdotnet

hitaspdotnet May 28, 2018

Come back on this feature and update please 😿 +1

hitaspdotnet commented May 28, 2018

Come back on this feature and update please 😿 +1

@natiki

This comment has been minimized.

Show comment
Hide comment
@natiki

natiki Jul 2, 2018

Contributor

Its worth reading https://github.com/dotnet-architecture/eShopOnContainers if you are doing anything micro services related. From that you should be able to use ABP as substance for each micro service.

Contributor

natiki commented Jul 2, 2018

Its worth reading https://github.com/dotnet-architecture/eShopOnContainers if you are doing anything micro services related. From that you should be able to use ABP as substance for each micro service.

@hikalkan hikalkan removed their request for review Oct 4, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment