/lib-rabbit-job-queue

RabbitMQ based job queue library for client and server.

Primary LanguageKotlinMIT LicenseMIT

RabbitMQ Job Queue

GitHub release (latest by date) Docs

Client/server library for utilizing RabbitMQ as a job queue.

Usage

Gradle
  implementation("org.veupathdb.lib:rabbit-job-queue:2.0.0")

Worker / Client

Java
var client = new QueueWorker(new QueueConfig());

client.onJob(job -> {

  // Do some work here.

  if (success)
    client.sendSuccess(new SuccessNotification(job.getJobID()));
  else
    client.sendError(new ErrorNotification(job.getJobID(), errorCode));
});
Kotlin
val client = QueueWorker {}

client.onJob {
  // Do some work here.

  if (success)
    client.sendSuccess(SuccessNotification(it.jobID))
  else
    client.sendError(ErrorNotification(it.jobID, errorCode))
}

Dispatcher / Server

Java
var dispatch = new QueueDispatcher(new QueueConfig());

dispatch.onSuccess(msg -> {
  // Do something with the job success
});

dispatch.onError(err -> {
  // Do something with the job error
});

dispatch.dispatch(new JobDispatch(
  someJobID,
  "jobType",
  body
));
Kotlin
val dispatch = QueueDispatcher {}

dispatch.onSuccess {
  // Do something with the job success
}

dispatch.onError {
  // Do something with the job error
}

dispatch.dispatch(JobDispatch(
  someJobID,
  "jobType",
  body
))

Warnings / Caveats

Message Ack Timeouts

RabbitMQ allows channels to be configured with their own timeout values, however these values cannot exceed the consumer_timeout value set in rabbitmq.conf file. By default, the consumer_timeout value is undefined, meaning channels can specify any timeout they choose, but care must be taken if configuring the RabbitMQ global consumer_timeout to ensure that any channel specific timeouts are shorter than the global value.