Skip to content

jiahengaa/Marmot

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

13 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Marmot

Marmot is a multi-threaded connection pooling secure for RabbitMQ client that supports Fanout, Direct, and Topic modes.Support DI.

icon

You should Know

  • The encoding format of transmission is UTF-8.
  • When Fanout and Direct,default autoAck is true

How To Use

Install-Package Marmot -Version 1.4.0
or
dotnet add package Marmot --version 1.4.0

Nuget address: https://www.nuget.org/packages/Marmot

Startup.cs

public void ConfigureServices(IServiceCollection services)
{
    services.UseMarmotMQ(opt =>
    {
        opt.HostName = "10.1.30.251";
        opt.Port = 5672;
        opt.UserName = "admin";
        opt.Password = "admin";
        opt.VirtualHost = "/";
    });
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_2);
    services.AddSwaggerCustom(Configuration, "MarmotTopicTest", "v1", UseValidateForSwagger, "MarmotTopicTest");
}

Fanout

  • Consumer
Task.Factory.StartNew(() =>
{
   await fConsumerClientFactory.Create("MarmotFanoutSample",
        (sender, e, channel) =>
        {
            Console.WriteLine($"RoutingKey:{e.RoutingKey},Body:{ Encoding.UTF8.GetString(e.Body)}");
            Console.WriteLine();
        }).StartListen(new TimeSpan(30000), new System.Threading.CancellationToken());
});
  • Publisher
await fPublish.PublishAsync(3333, "MarmotFanoutSample");

Topic

  • Consumer
 topicConsumerClientFactory.Create("MarmotExchange", "topic", queueName, true, false, (sender, e,consumer) =>
            {
                Console.WriteLine($"Queue:{queueName},RoutingKey:{e.RoutingKey},Body:{ Encoding.UTF8.GetString(e.Body)}");
                Console.WriteLine();
                consumer.BasicAck(e.DeliveryTag, false); //<-- how to ack
                //channel.BasicReject(deliveryTag, true); //<--how to reject
            }).StartListen(new[] { "aaa", "ljh-publish", "FF.#" }, new TimeSpan(30000), new System.Threading.CancellationToken());
  • Publisher
publishMessageSender.PublishAsync(new Person()
{
    Id = "0",
    Name = "xiaoming"
}, "MarmotExchange", "topic", "aaa", true, false, null);

publishMessageSender.PublishAsync(new Person()
{
    Id = "1",
    Name = "xiaoming1"
}, "MarmotExchange", "topic", "FF.933", true, false, null);

Direct

  • Consumer
dConsumerClientFactory.Create("MarmotExchangeDirect","",
    (sender, e,channel) =>
    {
        var body = e.Body;
        var message = Encoding.UTF8.GetString(body);
        var routingKey = e.RoutingKey;
        Console.WriteLine(" [x] Received '{0}':'{1}'", routingKey, message);
    }).StartListen(new[] { "aaa", "bbb", "cc" },
    new TimeSpan(30000), 
    new System.Threading.CancellationToken());
  • Publisher
await dPublish.PublishAsync(2333322,"aaa", "MarmotExchangeDirect");

Example ScreenShot

  • opened up several different models Consumers, Here are some screenshots of RabbitMQ Manager.
    1. Connection connection
    1. Channel channel
    1. Exchange Exchange
    1. Queue queue
    1. Diagnostic situation Diagnostic

Enjoy Coding

About

Marmot is a RabbitMQ Client, thread pools.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Languages