TaskQ.io Java SDK

Java SDK for TaskQ.io

License

License

Categories

Categories

Java Languages
GroupId

GroupId

io.taskq
ArtifactId

ArtifactId

taskq-io-java-sdk
Last Version

Last Version

0.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

TaskQ.io Java SDK
Java SDK for TaskQ.io
Project URL

Project URL

http://github.com/taskq-io/taskq-io-java-sdk
Source Code Management

Source Code Management

http://github.com/taskq-io/taskq-io-java-sdk

Download taskq-io-java-sdk

How to add to project

<!-- https://jarcasting.com/artifacts/io.taskq/taskq-io-java-sdk/ -->
<dependency>
    <groupId>io.taskq</groupId>
    <artifactId>taskq-io-java-sdk</artifactId>
    <version>0.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/io.taskq/taskq-io-java-sdk/
implementation 'io.taskq:taskq-io-java-sdk:0.0.1'
// https://jarcasting.com/artifacts/io.taskq/taskq-io-java-sdk/
implementation ("io.taskq:taskq-io-java-sdk:0.0.1")
'io.taskq:taskq-io-java-sdk:jar:0.0.1'
<dependency org="io.taskq" name="taskq-io-java-sdk" rev="0.0.1">
  <artifact name="taskq-io-java-sdk" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.taskq', module='taskq-io-java-sdk', version='0.0.1')
)
libraryDependencies += "io.taskq" % "taskq-io-java-sdk" % "0.0.1"
[io.taskq/taskq-io-java-sdk "0.0.1"]

Dependencies

compile (2)

Group / Artifact Type Version
org.apache.httpcomponents : httpclient jar 4.5.2
net.sf.json-lib : json-lib jar 2.4

test (1)

Group / Artifact Type Version
junit : junit jar 4.12

Project Modules

There are no modules declared in this project.

This is TaskQ.io SDK for Java.

This page explains how to use the SDK, but does not discuss all aspects of TaskQ.io. Please visit TaskQ.io to get a full picture.

Installation

To install the SDK in your project using Maven, use:

<dependency>
	<groupId>io.taskq</groupId>
	<artifactId>taskq-io-java-sdk</artifactId>
	<version>0.0.1</version>
</dependency>

Usage

Queueing tasks

TaskQ taskQ = new TaskQ();

// Optional - TaskQ will default to System.getenv("TASKQ_API_KEY") as set by Heroku
taskQ.setApiKey("1o2TzlloDCZK8PioXjocb5xm1A8GU5ItVR9u0ND682cKjy1GBH");

taskQ.useUrl("/tasks/sync_user")
	 .withParam("user_id", "L1mxeDbCIdv7COIUjuJ9")
	 .queue();

Running tasks

The example above will make TaskQ execute POST request to https://yourapp.herokuapp.com/tasks/sync_user with JSON payload:

{
	"user_id": "L1mxeDbCIdv7COIUjuJ9"
}

While handling tasks, always remember to check Authorization header; otherwise somebody else than TaskQ.io might be sending reqests to you! The SDK provides convenience method to do that:

taskQ.verify(authorizationHeader);

verify method will throw an exception in case of invalid Authorization header.

Below is an example of running tasks using Spring:

@RestController
@RequestMapping("/tasks")
public class TasksController {

	private final TaskQ taskQ;
	
	@Autowired
	public TasksController(TaskQ taskQ) {
		this.taskQ = taskQ;
	}

	@RequestMapping(value="/sync_user", method=HttpMethod.GET)
	public void syncUser(@RequestBody UserIdDTO userIdDTO, @RequestHeader("Authorization") String authorization) {
		taskQ.verify(authorization);
		...
	}
}

public class UserIdDTO {
	
	private final String userId;
	
	@JsonCreator
	public UserIdDTO(@JsonProperty("user_id") String userId) {
		this.userId = userId;
	}
	
	public String getUserId() {
		return userId;
	}
}

Your feedback is very welcome! Please use Github's issue tracker to report issues, request features, etc.

Versions

Version
0.0.1