.Net Core Application RabbitMQ, and simple packaging

First of all, extremely grateful that we can still find time to read my article, very grateful. Today I bring is .Net Core application RabbitMQ, and simple package. Because yesterday's article said write today, so today must write it. Xiao Bian read a lot of information, some want a design to meet their own needs, but also facilitate the expansion, while ensuring the safety of simple package. In turn to a classic article, if you use RabbitMQ just to deal with high concurrency, so that messages can be asynchronous processing, you can use the following links. Due to the small series now doing is for their own services distributed architecture, in the middle need to achieve real-time communication, this is not very suitable for small series. So a small series of own package, but it can also refer to. https://mp.weixin.qq.com/s/Hj5R09StmMgRiCDnf-zLVw small series directly below the map, the source code is attached, if not understood basic use RabbitMQ may otherwise find. First, write a RabbitMQHelper, we created in the constructor connection factory, connection, channel switch. Proposals into the configuration file, easy to post-maintenance .

Then we use a generic way to write SendMsg method, the benefits of generics much to say here

Receive method is followed, where I do not use generic, is returned directly to the string out, in order to adapt to different business scenarios can be custom serialization.

Entrusted used here is to separate business and Helper class, easy to support other businesses.

Careful comrades will find the constructor set switch name, function name in setting up the queue, this design was to write the following MQHelperFactory. Here we can customize each switch is also convenient to call, and can conceal we use RabbitMQ, reduce the impact of a late replacement for other MQ middleware development.

Then, we finished writing, the actual call only one line of code, but also to accept the message entrusted used, the separation of the good. If you worry each time you create will affect the efficiency, you can use the singleton pattern, or the IOC with the Singleton pattern to use. Here is not introduced one by one, please according to their own design business scenarios.

源码地址:
https://github.com/SkylerSkr/RabbitMQHelper

Guess you like

Origin www.cnblogs.com/owenzh/p/11087911.html