https://github.com/cobbzilla/jestrel
Simple Java client for Kestrel message queue
https://github.com/cobbzilla/jestrel
Last synced: 10 months ago
JSON representation
Simple Java client for Kestrel message queue
- Host: GitHub
- URL: https://github.com/cobbzilla/jestrel
- Owner: cobbzilla
- License: apache-2.0
- Created: 2013-03-21T00:09:09.000Z (over 13 years ago)
- Default Branch: master
- Last Pushed: 2016-08-11T22:33:44.000Z (almost 10 years ago)
- Last Synced: 2024-04-16T18:57:51.453Z (about 2 years ago)
- Language: Java
- Homepage:
- Size: 25.4 KB
- Stars: 6
- Watchers: 5
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
jestrel
=======
Simple Java client for Kestrel
### Motivation
Working with Kestrel queues should be easy. But after scouring the web, I couldn't find a "native" Kestrel client
for Java, only some memcached clients that had some support for Kestrel-specific stuff.
So, building on top of the xmemcached library on googlecode, I wrote jestrel
### System Requirements
* Java 7
* Maven 3
### Building
mvn package
### Usage
#### Initialize the client library
// Setup configuration
Properties kestrelProperties = new Properties();
// Max # of connections to kestrel. default is 1
kestrelProperties.setProperty("kestrelConnectionPoolSize", "10");
// Comma-separated list of hostname:port of all kestrel servers to use. required.
kestrelProperties.setProperty("kestrelHosts", "kestrel-1:22133, kestrel-2:22133");
// How often should the client drop its connection to kestrel and reconnect. default is 5 minutes
// If you are using multiple kestrel servers, this will ensure that no kestrel server sits idle with no clients
kestrelProperties.setProperty("kestrelReconnectIntervalInMinutes", "5");
// Create a client
MqClientFactory clientFactory = new MqClientFactory();
MqClient client = clientFactory.createClient(KestrelClient.class, kestrelProperties);
### Sending a message
String queueName = "some_queue";
MqProducer producer = client.getProducer(queueName);
producer.send("some message");
### Registering a queue consumer
// I'm using an inline class here for brevity.
// You will probably want to create your own class that implements the MqConsumer interface.
MqConsumer consumer = new MqConsumer() {
/**
* @param o The message, which will be a String
* @exception Exception If any exception is thrown, the message will be put onto the errorQueue (unless it was set to null when the consumer was registered)
*/
public void onMessage(Object o) throws Exception {
System.out.println("received: " + o.toString());
}
};
String queueName = "some_queue";
String errorQueueName = "some_queue_error";
client.registerConsumer(consumer, queueName, errorQueueName);