-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 5ab51da
Showing
32 changed files
with
14,414 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
logs | ||
project/project | ||
project/target | ||
target | ||
tmp | ||
.history | ||
dist | ||
/.idea | ||
/*.iml | ||
/out | ||
/.idea_modules | ||
/.classpath | ||
/.project | ||
/RUNNING_PID | ||
/.settings | ||
/.target/ | ||
/bin/ | ||
/.cache |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2015 btnguyen2k | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy of | ||
this software and associated documentation files (the "Software"), to deal in | ||
the Software without restriction, including without limitation the rights to | ||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of | ||
the Software, and to permit persons to whom the Software is furnished to do so, | ||
subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS | ||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR | ||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER | ||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN | ||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
queue-jclient | ||
============= | ||
|
||
Java client for [https://github.com/btnguyen2k/queue-server](https://github.com/btnguyen2k/queue-server). | ||
|
||
## Release-notes ## | ||
|
||
Latest release: `0.1.0`. | ||
|
||
See [RELEASE-NOTES.md](RELEASE-NOTES.md). | ||
|
||
## Usage ## | ||
|
||
```java | ||
// obtain an IQueueClient instance: REST client | ||
IQueueClient queueClient = new RestQueueClient().setQueueServerUrl("http://localhost:8080").init(); | ||
//or preferred way | ||
IQueueClient queueClient = RestQueueClientFactory.newQueueClient("http://localhost:8080"); | ||
|
||
// obtain an IQueueClient instance: Thrift client | ||
IQueueClient queueClient = new ThriftqueueClient().setQueueServerHostsAndPorts("localhost:9090,host2:9090,host3:9090").init(); | ||
//or preferred way | ||
IQueueClient queueClient = ThriftqueueClientFactory.newQueueClient("localhost:9090,host2:9090,host3:9090"); | ||
// Thrift client supports host fail-over! | ||
|
||
// obtain an IQueueClient instance: Thrift-over-http client | ||
IQueueClient queueClient = new ThriftHttpQueueClient().setQueueServerUrls("http://localhost:8080/thrift,http://host2/thrift,http://host3/thrift").init(); | ||
//or preferred way | ||
IQueueClient queueClient = ThriftHttpQueueClientFactory.newQueueClient("http://localhost:8080/thrift,http://host2/thrift,http://host3/thrift"); | ||
// Thrift client supports host fail-over! | ||
``` | ||
|
||
```java | ||
// do some cool stuff | ||
|
||
// initialize a queue | ||
QueueResponse response = queueClient.initQueue("secret", "queue_name"); | ||
|
||
// queue a message | ||
QueueResponse response = queueClient.queue("secret", "queue_name", "message".getBytes()); | ||
// or, queue a message | ||
QueueMessage msg = new QueueMessage(); | ||
msg.content("message content".getBytes()); | ||
QueueResponse response = queueClient.queue("secret", "queue_name", msg); | ||
|
||
// take a message out of queue | ||
QueueResponse response = queueClient.take("secret", "queue_name"); | ||
QueueMessage msg = response.queueMessage; | ||
|
||
// call method "finish" when done with the message to cleanup ephemeral storage | ||
QueueResponse response = queueClient.finish("secret", "queue_name", msg); | ||
|
||
// or, requeue the message to retry latter | ||
QueueResponse response = queueClient.requeue("secret", "queue_name", msg); | ||
``` | ||
|
||
## License ## | ||
|
||
See [LICENSE.txt](LICENSE.txt) for details. Copyright (c) 2015 btnguyen2k. | ||
|
||
Third party libraries are distributed under their own license(s). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
queue-jclient Release Notes | ||
=========================== | ||
|
||
Java client for [https://github.com/btnguyen2k/queue-server](https://github.com/btnguyen2k/queue-server). | ||
|
||
2015-06-16: v0.1.0 | ||
------------------ | ||
First release: | ||
|
||
- REST & Thrift client |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,119 @@ | ||
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
<modelVersion>4.0.0</modelVersion> | ||
|
||
<parent> | ||
<groupId>com.github.ddth</groupId> | ||
<artifactId>ddth-parent</artifactId> | ||
<version>2</version> | ||
</parent> | ||
|
||
<artifactId>queue-jclient</artifactId> | ||
<version>0.1.0-SNAPSHOT</version> | ||
<packaging>jar</packaging> | ||
|
||
<name>queue-jclient</name> | ||
<description>Java client for queue-server</description> | ||
<url>https://github.com/btnguyen2k/queue-jclient</url> | ||
|
||
<scm> | ||
<url>[email protected]:btnguyen2k/queue-jclient</url> | ||
<connection>scm:git:[email protected]:btnguyen2k/queue-jclient</connection> | ||
<developerConnection>scm:git:[email protected]:btnguyen2k/queue-jclient</developerConnection> | ||
</scm> | ||
<developers> | ||
<developer> | ||
<id>btnguyen2k</id> | ||
<name>Thanh Ba Nguyen</name> | ||
<email>[email protected]</email> | ||
</developer> | ||
</developers> | ||
|
||
<properties> | ||
<skipTests>true</skipTests> | ||
<version.jackson>2.5.3</version.jackson> | ||
</properties> | ||
|
||
<dependencies> | ||
<dependency> | ||
<groupId>junit</groupId> | ||
<artifactId>junit</artifactId> | ||
<version>${version.junit}</version> | ||
<scope>test</scope> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.yammer.metrics</groupId> | ||
<artifactId>metrics-core</artifactId> | ||
<version>2.2.0</version> | ||
<scope>test</scope> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.github.ddth</groupId> | ||
<artifactId>ddth-commons</artifactId> | ||
<version>0.3.1</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>com.github.ddth</groupId> | ||
<artifactId>ddth-thriftpool</artifactId> | ||
<version>0.2.1.3</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.thrift</groupId> | ||
<artifactId>libthrift</artifactId> | ||
<version>0.9.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpasyncclient</artifactId> | ||
<version>4.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpclient</artifactId> | ||
<version>4.4.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.httpcomponents</groupId> | ||
<artifactId>httpcore</artifactId> | ||
<version>4.4.1</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>org.apache.commons</groupId> | ||
<artifactId>commons-io</artifactId> | ||
<version>1.3.2</version> | ||
</dependency> | ||
|
||
<dependency> | ||
<groupId>org.jodd</groupId> | ||
<artifactId>jodd-http</artifactId> | ||
<version>3.6.5</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-core</artifactId> | ||
<version>${version.jackson}</version> | ||
</dependency> | ||
<dependency> | ||
<groupId>com.fasterxml.jackson.core</groupId> | ||
<artifactId>jackson-databind</artifactId> | ||
<version>${version.jackson}</version> | ||
</dependency> | ||
</dependencies> | ||
|
||
<build> | ||
<plugins> | ||
<plugin> | ||
<artifactId>maven-surefire-plugin</artifactId> | ||
<configuration> | ||
<skipTests>${skipTests}</skipTests> | ||
<systemPropertyVariables> | ||
<log4j.configuration>file:${basedir}/etc/log4j.xml</log4j.configuration> | ||
</systemPropertyVariables> | ||
</configuration> | ||
</plugin> | ||
</plugins> | ||
</build> | ||
</project> |
105 changes: 105 additions & 0 deletions
105
src/main/java/com/github/btnguyen2k/queue/jclient/IQueueClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
package com.github.btnguyen2k.queue.jclient; | ||
|
||
/** | ||
* Client API to interact with queue-server. | ||
* | ||
* @author Thanh Nguyen <[email protected]> | ||
* @since 0.1.0 | ||
*/ | ||
public interface IQueueClient { | ||
|
||
/** | ||
* Checks if a queue exists. | ||
* | ||
* @param secret | ||
* @param queueName | ||
* @return | ||
*/ | ||
public QueueResponse queueExists(String secret, String queueName); | ||
|
||
/** | ||
* Creates & Initializes a new queue. | ||
* | ||
* @param secret | ||
* @param queueName | ||
* @return | ||
*/ | ||
public QueueResponse initQueue(String secret, String queueName); | ||
|
||
/** | ||
* Puts a message to a queue. | ||
* | ||
* @param secret | ||
* @param queueName | ||
* @param content | ||
* @return | ||
*/ | ||
public QueueResponse queue(String secret, String queueName, byte[] content); | ||
|
||
/** | ||
* Puts a message to a queue. | ||
* | ||
* @param secret | ||
* @param queueName | ||
* @param queueMessage | ||
* @return | ||
*/ | ||
public QueueResponse queue(String secret, String queueName, QueueMessage queueMessage); | ||
|
||
/** | ||
* Re-queues a message. | ||
* | ||
* @param secret | ||
* @param queueName | ||
* @param queueMessage | ||
* @return | ||
*/ | ||
public QueueResponse requeue(String secret, String queueName, QueueMessage queueMessage); | ||
|
||
/** | ||
* Re-queues a message silently. | ||
* | ||
* @param secret | ||
* @param queueName | ||
* @param queueMessage | ||
* @return | ||
*/ | ||
public QueueResponse requeueSilent(String secret, String queueName, QueueMessage queueMessage); | ||
|
||
/** | ||
* Called when finish processing the message to cleanup ephemeral storage. | ||
* | ||
* @param secret | ||
* @param queueName | ||
* @param queueMessage | ||
* @return | ||
*/ | ||
public QueueResponse finish(String secret, String queueName, QueueMessage queueMessage); | ||
|
||
/** | ||
* Takes a message from a queue. | ||
* | ||
* @param secret | ||
* @param queueName | ||
* @return | ||
*/ | ||
public QueueResponse take(String secret, String queueName); | ||
|
||
/** | ||
* Gets number of items currently in a queue. | ||
* | ||
* @param secret | ||
* @param queueName | ||
* @return | ||
*/ | ||
public QueueSizeResponse queueSize(String secret, String queueName); | ||
|
||
/** | ||
* Gets number of items currently in a queue's ephemeral storage. | ||
* | ||
* @param secret | ||
* @param queueName | ||
* @return | ||
*/ | ||
public QueueSizeResponse ephemeralSize(String secret, String queueName); | ||
} |
Oops, something went wrong.