2011-08-03 5 views
12

저희 회사는 Python 기반 웹 사이트와 Django/Celery 및 RabbitMQ를 통해 통신하는 Python 기반 작업자 노드를 가지고 있습니다. Celery 기반 작업자에게 작업을 제출해야하는 Java 기반 응용 프로그램이 있습니다. Java에서 RabbitMQ로 작업을 보낼 수는 있지만 샐러리 기반 직원은 결코 작업을 수행하지 않습니다. 두 가지 형태의 제출물에 대한 패킷 캡처를 살펴보면 차이점이 있지만, 많은 부분이 바이너리이기 때문에 어떻게 설명 할 지 짐작할 수 없기 때문에 디코딩에 대한 설명서를 찾을 수 없습니다. 여기 누구든지 Java/RabbitMQ와 Celery를 함께 사용하는 데 대한 참조 또는 경험이 있습니까?Django/Celery와의 상호 운용 Java에서

답변

12

해결책을 찾았습니다. RabbitMQ 용 Java 라이브러리는 exchange/queues/routekeys를 참조합니다. Celery에서 대기열 이름은 실제로 Java 라이브러리에서 참조되는 교환에 맵핑됩니다. 기본적으로 Celery 큐는 단순히 "셀러리"입니다.

CELERY_ROUTES = { 
    'mypackage.myclass.runworker'  : {'queue':'myqueue'}, 
} 

그런 다음 자바 기반의 코드는 다음과 같은 일을 할 필요가 : 장고 설정 "이 MyQueue"다음 구문을 사용하여 호출 큐를 정의하면

 ConnectionFactory factory = new ConnectionFactory(); 
     Connection connection = null ; 
     try { 
      connection = factory.newConnection(mqHost, mqPort); 
     } catch (IOException ioe) { 
      log.error("Unable to create new MQ connection from factory.", ioe) ; 
     } 

     Channel channel = null ; 
     try { 
      channel = connection.createChannel(); 
     } catch (IOException ioe) { 
      log.error("Unable to create new channel for MQ connection.", ioe) ; 
     } 

     try { 
      channel.queueDeclare("celery", false, false, false, true, null); 
     } catch (IOException ioe) { 
      log.error("Unable to declare queue for MQ channel.", ioe) ; 
     } 

     try { 
      channel.exchangeDeclare("myqueue", "direct") ; 
     } catch (IOException ioe) { 
      log.error("Unable to declare exchange for MQ channel.", ioe) ; 
     } 

     try { 
      channel.queueBind("celery", "myqueue", "myqueue") ; 
     } catch (IOException ioe) { 
      log.error("Unable to bind queue for channel.", ioe) ; 
     } 

      // Generate the message body as a string here. 

     try { 
      channel.basicPublish(mqExchange, mqRouteKey, 
       new AMQP.BasicProperties("application/json", "ASCII", null, null, null, null, null, null, null, null, null, "guest", null, null), 
       messageBody.getBytes("ASCII")); 
     } catch (IOException ioe) { 
      log.error("IOException encountered while trying to publish task via MQ.", ioe) ; 
     } 

그것은 그냥 밝혀 용어의 차이.

+0

팁을 주셔서 감사합니다. 예외 사용은 상당히 잘못되었습니다. – Debriter

관련 문제