2011-05-06 19:38:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								# RabbitMQ Recent History Cache
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-10-15 05:58:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Keeps track of the last 20 messages that passed through the exchange. Every time a queue is bound to the exchange it delivers that last 20 messages to them. This is useful for implementing a very simple __Chat History__  where clients that join the conversation can get the latest messages.
							 
						 
					
						
							
								
									
										
										
										
											2011-05-06 19:38:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-15 18:24:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Exchange yype: `x-recent-history` .
							 
						 
					
						
							
								
									
										
										
										
											2011-05-06 19:38:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-27 03:52:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Installation ##
  
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-15 18:24:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								This plugin ships with RabbitMQ. 
							 
						 
					
						
							
								
									
										
										
										
											2015-12-27 22:38:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-15 18:24:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Like all other plugins, it must be enabled before it can be used:
							 
						 
					
						
							
								
									
										
										
										
											2015-04-14 22:10:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```bash
							 
						 
					
						
							
								
									
										
										
										
											2023-04-15 18:24:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								[sudo] rabbitmq-plugins enable rabbitmq_recent_history_exchange
							 
						 
					
						
							
								
									
										
										
										
											2015-04-14 22:10:24 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
									
										
										
										
											2014-03-27 03:52:32 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								## Usage ##
  
						 
					
						
							
								
									
										
										
										
											2014-03-27 03:05:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-15 18:24:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Creating an exchange
  
						 
					
						
							
								
									
										
										
										
											2014-03-27 03:25:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								To create a _recent history exchange_ , just declare an exchange providing the type `"x-recent-history"` .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								channel.exchangeDeclare("logs", "x-recent-history");
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-15 18:24:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Providing a custom history length
  
						 
					
						
							
								
									
										
										
										
											2014-03-27 03:25:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2014-03-27 03:05:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								Typically this exchange will store the latest 20 messages sent over
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								the exchange. If you want to set a different cache length, then you
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								can pass a `"x-recent-history-length"`  argument to `exchange.declare` .
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								The argument must be an integer greater or equal to zero.
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								For example in Java:
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								```java
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								Map< String ,  Object >  args = new HashMap< String ,  Object > ();
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								args.put("x-recent-history-length", 60);
							 
						 
					
						
							
								
									
										
										
										
											2014-03-27 03:25:38 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								channel.exchangeDeclare("rh", "x-recent-history", false, false, args);
							 
						 
					
						
							
								
									
										
										
										
											2014-03-27 03:05:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								```
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-15 18:24:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								### Preventing some messages from being stored
  
						 
					
						
							
								
									
										
										
										
											2014-03-27 03:05:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
							 
							
								
							 
							
								 
							
							
								In case you would like to not store certain messages, just
							 
						 
					
						
							
								
									
										
										
										
											2014-03-27 03:15:33 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								add the header `"x-recent-history-no-store"`  with the value `true`  to
							 
						 
					
						
							
								
									
										
										
										
											2014-03-27 03:05:06 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								the message.
							 
						 
					
						
							
								
									
										
										
										
											2013-11-28 14:50:47 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2023-04-15 18:24:02 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## Disabling the Plugin
  
						 
					
						
							
								
									
										
										
										
											2014-03-27 03:32:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2024-11-19 18:44:58 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								When you disable this plugin, it will delete all the cached messages.
							 
						 
					
						
							
								
									
										
										
										
											2014-03-27 03:32:29 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2011-10-15 05:58:22 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								## License
  
						 
					
						
							
								
									
										
										
										
											2011-05-06 19:38:48 +08:00 
										
									 
								 
							 
							
								
							 
							
								 
							
							
								
							 
						 
					
						
							
								
									
										
										
										
											2020-03-09 15:48:26 +08:00 
										
									 
								 
							 
							
								
									
										 
								
							 
							
								 
							
							
								See LICENSE.