All Projects → SmartBear → JCeleryWorker

SmartBear / JCeleryWorker

Licence: other
A simple Java worker for Celery

Programming Languages

java
68154 projects - #9 most used programming language

JCeleryWorker

A very simple Celery worker for Java.

Currently only supports RabbitMQ and JSON.

Usage

This replaces the worker from the First Steps with Celery tutoral:

public class DemoApp {
	public static void main(String[] _) throws Exception {
		JobService celeryService = new CeleryService();
      		celeryService.setInvokeHandler( new TaskHandler<InvokeJob>()
      		{
      			@Override
      			public void handle( InvokeJob t ) throws IOException
      			{
      				switch( t.getMethod() )
      				{
      					case "tasks.add":
      						t.complete( Job.Status.SUCCESS, add( t ) );
      				}
      			}
      		} );

      		celeryService.setRevokeHandler( new TaskHandler<InvokeJob>()
      		{
      			@Override
      			public void handle( InvokeJob t ) throws IOException
      			{
      				switch( t.getMethod() )
      				{
      					case "revoke":
      						t.complete( Job.Status.REVOKED );
      				}
      			}
      		} );

      		celeryService.startService();

		// ...
	}

	private static long add(CeleryTask t) {
		long x = (long) t.args.get(0);
		long y = (long) t.args.get(1);
		return x + y;
	}
}
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].