[rabbitmq-discuss] Question on Java Client

Deven Phillips deven at dns.com
Thu Mar 17 06:17:38 GMT 2011


I am working in an environment where Java/Python interop is important, 
so I have been trying to get the Java RabbitMQ client API and the 
Django/Celery tasks to work together. I can now successfully submit jobs 
to the CeleryD task queue and have them executed, but the call to 
channel.basicPublish() hangs.... It appears to be blocking while waiting 
on a response, but using a traffic sniffer, I see that the response has 
been received already. Could anyone suggest steps to find the cause? Is 
there a way to turn up the logging on the RabbitMQ API?

Anyhow, Thanks in advance for the assistance. Here are the vital stats:

Platform: Ubuntu 64 - 10.10 (Maverick)
RabbitMQ Version: 1.7.2
RabbitMQ API Version: 1.7.2
Celery Version: 2.2.4
Python Version: 2.6.5

Example Code:

package com.dns.celery.publisher;

import com.rabbitmq.client.AMQP;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.GregorianCalendar;
import java.util.TimeZone;
import java.util.UUID;
import org.apache.log4j.Appender;
import org.apache.log4j.ConsoleAppender;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.PatternLayout;

/**
  * A test application to submit a job to RabbitMQ which is compatible 
with Celery tasks.
  * @author <a href="deven at dns.com">Deven Phillips</a>
  */
public class Main {

     /**
      * @param args the command line arguments
      */
     public static void main(String[] args) throws Exception {
         Logger rootLog = Logger.getRootLogger() ;
         Appender console = new ConsoleAppender(new 
PatternLayout("%d{yyyy-MM-dd HH:mm:ss,SSS} - %5p [%t] (%F:%L) - %m%n")) ;
         rootLog.addAppender(console) ;
         rootLog.setLevel(Level.DEBUG) ;
         String queueName = "my_queue" ;

         ConnectionFactory factory = new ConnectionFactory();
         Connection connection = factory.newConnection("127.0.0.1");
         Channel channel = connection.createChannel();

         channel.queueDeclare(queueName, false, false, false, true, null);

         String uuId = UUID.randomUUID().toString() ;
         rootLog.info("TASK ID: "+uuId) ;
         DateFormat df1 = new SimpleDateFormat("yyyy-MM-dd") ;
         df1.setTimeZone(TimeZone.getTimeZone("GMT"));
         DateFormat df2 = new SimpleDateFormat("HH:mm:ss.S") ;
         df2.setTimeZone(TimeZone.getTimeZone("GMT"));
         Calendar cal = new GregorianCalendar() ;
         String eta = 
df1.format(cal.getTime())+"T"+df2.format(cal.getTime())+"0000" ;
         String messageBody = "{\"id\": \""+uuId+"\",\"task\": 
\"dns.tasks.build.domain\", \"args\": [76182], \"kwargs\": {}, 
\"retries\": 0, \"eta\": \""+eta+"\"}" ;
         rootLog.info(messageBody);
         byte[] msgBytes = messageBody.getBytes("ASCII") ;
         rootLog.info("Made it here!!") ;
         channel.basicPublish(queueName, queueName,
                      new AMQP.BasicProperties
                        ("application/json", null, null, null,
                         null, null, null, null,
                         null, null, null, "guest",
                         null, null),messageBody.getBytes("ASCII")) ;
     }
}


More information about the rabbitmq-discuss mailing list