当前位置:网站首页>Unfair distribution
Unfair distribution
2022-07-24 21:26:00 【A light wind and light clouds】
In the beginning, we learned RabbitMQ The message is distributed in rotation , But in some scenarios, this strategy is not very good , For example, there are two consumers dealing with tasks , One of the consumers 1 Processing tasks is very fast , And another consumer 2
Processing speed is slow , At this time, we still use the rotation training distribution, so that the fast processing consumer is idle for a large part of the time , The slow consumer has been working , This distribution method is actually not very good in this case , however
RabbitMQ Not knowing this, it is still fairly distributed .
To avoid that , We can set parameters channel.basicQos(1);
public class UnfairWork {
public final static String QUEUE_NAME="hello3";
public static void main(String[] args) throws Exception {
System.out.println("c1 Short response ....");
Channel channel = untils.getChannel();
/**
* Unfair distribution
* Set parameters
*/
int prefetchCount=1;
channel.basicQos(1);
/**
* Consumer information
* 1. Which queue to consume
* 2. Whether to answer automatically after successful consumption ,true Auto answer ,false manual
* 3. The callback content of unsuccessful consumption by consumers 1
* 4. Consumer canceled callback
*
*/
// Statement receive messages
DeliverCallback deliverCallback=(consumerTag, delivery)->{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
//1. Message tags
// 2.false It means that only the received transmitted information is answered ,true To answer all messages, including the delivered messages
channel.basicAck(delivery.getEnvelope().getDeliveryTag(),false);
System.out.println(" Messages received "+new String(delivery.getBody()));
};
// Cancel Callback of message
CancelCallback cancelCallback= consumerTag -> {
System.out.println(consumerTag+" Message consumer interrupt ");
};
channel.basicConsume(QUEUE_NAME,false,deliverCallback,cancelCallback);
}
}
/**
* This is the same code as the round robin
*/
public class UnfairProduce {
public static final String QUEUE_NAME="hello3";
public static void main(String[] args) throws IOException, TimeoutException {
Channel channel = untils.getChannel();
channel.queueDeclare(QUEUE_NAME,false,false,false,null);
// Receive messages from control too
Scanner scanner = new Scanner(System.in);
while(scanner.hasNext())
{
String message=scanner.next();
channel.basicPublish("",QUEUE_NAME,null,message.getBytes(StandardCharsets.UTF_8));;
System.out.println(" Send message complete "+message);
}
}
}
边栏推荐
- Spark related FAQ summary
- MySQL - multi table query - seven join implementations, set operations, multi table query exercises
- [SOC] the first project of SOC Hello World
- Baidu interview question - judge whether a positive integer is to the power of K of 2
- Detailed OSPF configuration of layer 3 switch / router [Huawei ENSP experiment]
- A simple method of converting SVG to PDF
- What are intelligent investment advisory products?
- [advanced data mining technology] Introduction to advanced data mining technology
- PC port occupation release
- Is it safe for Hengtai securities to open an account?
猜你喜欢
![[shallow copy and deep copy], [heap and stack], [basic type and reference type]](/img/cc/d43e0046d83638f381c34b463f64a2.png)
[shallow copy and deep copy], [heap and stack], [basic type and reference type]

RESNET interpretation and 1 × 1 Introduction to convolution

Lecun proposed that mask strategy can also be applied to twin networks based on vit for self supervised learning!

Opencv learning Day2

what? Does the multi merchant system not adapt to app? This is coming!

Preview and save pictures using uni app

Native applets are introduced using vant webapp

Lenovo Filez helps Zhongshui North achieve safe and efficient file management

Drive subsystem development

APR learning failure problem location and troubleshooting
随机推荐
Lazily doing nucleic acid and making (forging health code) web pages: detained for 5 days
whistle ERR_ CERT_ AUTHORITY_ INVALID
[install PG]
Lecun proposed that mask strategy can also be applied to twin networks based on vit for self supervised learning!
Native applets are introduced using vant webapp
Build your own stock analysis system based on b\s architecture
[verification of ID number]
Quick sort
APR learning failure problem location and troubleshooting
Understand MySQL index and b+tree in an easy to understand way (supreme Collection Edition)
One bite of Stream(7)
Transport layer protocol parsing -- UDP and TCP
You must make good use of MySQL and JSON
Pychart tutorial: 5 very useful tips
Baidu PaddlePaddle easydl helps improve the inspection efficiency of high-altitude photovoltaic power stations by 98%
Overloaded & lt; for cv:: point;, But VS2010 cannot find it
[blind box app mall system] function introduction after online unpacking
Scientific computing toolkit SciPy Fourier transform
Metauniverse: technological evolution, industrial ecology and big country game
Leetcode skimming -- bit by bit record 017