Integration and combat

And Spring  Integration

pom  file

  Use Maven, 4.3.11 used here, so here is the introduction of the rabbit  is  2.0.0, if compatibility of your own, then go to Spring  official website to check

 

Here add, spring  introduced also for native packaging

 

 

 

 

 

 

Unified configuration

Increase the profile name space

 

 

 

Connection configuration:

  Client connections

 

  Configuration Management

 

 

 

Producer end (basic configuration)

  RabbitTemplate

 

Such declarations or below are also possible.

 

 

 

Switch queues and

And switches may be increased in the queue configuration file producer

    

When sending a message, use rabbitTemplate can. Also be configured to message attributes MessageProperties.

 

 

 

 

 

 

Here Again, producers and consumers can affirm switches, affirmed queue, binding relationship, the general process is the same configuration producers and consumers, so as to prevent the event, if the producer or the consumer launch alone, or send consumption data is not a problem.

 

Consumers end (base configuration)

Queue and switches,

  Consumers may also be configured and switch queues, and the queue and the specified route key switch binding

 

 

 

Consumers bean

Two ways, one configuration file a comment custom profile

 

 

Annotation defines

 

 

 

 

Monitor container

The consumer bean  and queue link

 

 

 

Code

Consumers can achieve MessageListener interface.

 

 

 

Producers end (Advanced Configuration)

The sender confirmation callback

  And native implementations similar code, see below rq-order  package configuration

 

 

 

 

 

 

Failure callback notifications

Implementation and native almost

 

 

 

Consumers end (Advanced Configuration)

Manual confirmation

  Implementation and native almost

 

 

 

 

 

 

Channel channel can get here  , then, the specific operation on the same and native. Recall that in each case the native will be according to your business scenarios to deal with.

 

Qos

 

 

 

And SpringBoot  Integration

pom  file

Springboot this  version we are using  2.1.1, maintain and we explain Springboot a  version consistency

 

 

Here SpringBoot  is also a native packaging, empathy and  Spring  introduced in  RabbitMQ

 

 

 

Unified configuration

Configuring the connection configuration

  This includes virtual machine, add the sender to confirm that we are

 

 

Connection factory

A configuration class

 

 

 

 

RabbitTemplate

 

 

Queue and switches and binding relationship

  Producers may be configured RabbitConfig  increase the queue class and switches

 

The default switch (direct)

  By default, declare a queue if there is no binding relationship is established with the switch, the system defaults to assign a Default  switch (which is also a multiple queues), matching the default queue name

 

 

Topic type

 

 

Fanout Type

 

The sender failure notification

 

 

The sender confirmation callback

 

 

 

Producers

By default (direct binding exchanger queue)

HelloReceiver、UserReceiver

 

Topic switches (bound queue)

TopicEmailMessageReceiver, TopicUserMessageReceiver

 

Fanout switches (bound queue)

FanoutReceiver

 

consumer

By default (direct binding exchanger queue)

  HelloReceiver、UserReceiver

 

Topic switches (bound queue)

  TopicEmailMessageReceiver, TopicUserMessageReceiverFanout switches (bound queue)

  FanoutReceiver

 

Demonstration effect

A common type (direct  exchange) test

  http://localhost:8080/rabbit/hello

 

 

Producers

 

 

consumer

Simple consumers

 

Consumers manual confirmation

 

 
Broadcast type (Fanout  exchange) test

http://localhost:8080/rabbit/fanoutTest

 

 

Producers

 

 

 

consumer

Simple consumers

 

 

Topic  type ( Topic  exchange) test

http://localhost:8080/rabbit/topicTest

 

 

Practical Application - Application of Decoupling

Scenes:

 

  Under customer orders to buy goods after a successful order processing, inventory to deduct, in this scene, the order system is a producer, consumer inventory system.

  Inventory must be deducted in the business, the stock can be deducted directly, no inventory or below a certain threshold, you can deduct success, but to notify other systems (such as the procurement notice procurement system as soon as possible, inform the customer orders we will transfer cargo system as soon as possible).

 

RPC  achieve

RPC over  achieve, you can see  RPC  cause coupling. Once the inventory system fails, the system will follow orders fail. We hope that the inventory system failure itself, do not affect order execution system on business processes, decoupling ordering system and inventory system.

 

 

RabbitMQ  implementation

  For the realization of our message mode, in order to ensure that inventory must be deducted, we have to consider a few questions:

  1, the system orders issued Mq  deductions stock messaging server must be  Mq  server receives, it means using the sender confirmation.

  2, Mq  server must always be kept in stock before deduction of the message is correctly handle inventory service, you need message persistence.

  3, an inventory server is a problem, deductions inventory of messages to be able to service other normal inventory process, we need to confirm their own consumption, which means consumers can not use automatic confirmation, but should use the manual confirmation.

 

  Therefore, producers need to order system side , the queue configuration file and switches for persistence, when persistent message, the sender of the configuration and confirmation code.

  Inventory system so consumers here to manually confirm.

Guess you like

Origin www.cnblogs.com/Soy-technology/p/11610506.html