Scheduling Celery task from Java: "Received and deleted unknown message. Wrong destination"
<p>I'm trying to schedule Celery task from Java.</p>

<p>I'm sending task to RabbitMQ like this:</p>

<pre><code>ConnectionFactory factory = new ConnectionFactory();
factory.setHost("localhost");
connection = factory.newConnection();
channel = connection.createChannel();

boolean durable = true;
channel.queueDeclarePassive("celery");
channel.exchangeDeclarePassive("celery");

String MESSAGE_FORMAT = "{\"id\": \"%s\", " + "\"task\": \"%s\", " + "\"args\": [\"%s\"]}";
message = String.format(MESSAGE_FORMAT, UUID.randomUUID().toString(), "celery.tasks.add", "2501");
channel.basicPublish("celery", "celery", null, message.getBytes("UTF-8"));
</code></pre>

<p>The messages is sent:</p>

<pre><code>| routing_key | exchange | message_count |                                                  payload                                                  | payload_bytes | payload_encoding | properties | redelivered |
+-------------+----------+---------------+-----------------------------------------------------------------------------------------------------------+---------------+------------------+------------+-------------+
| celery      |          | 0             | {"id": "7421864e-aff3-4f2f-b274-9d5eacfc8941", "task": "celery.tasks.add", "args": ["2501"]} | 105           | string           |            | False 
</code></pre>

<p>But when I start worker:</p>

<pre><code>celery -A tasks worker --loglevel=info
</code></pre>

<p>I get a message:</p>

<pre><code>[2016-03-02 16:23:08,457: WARNING/MainProcess] Received and deleted unknown message. Wrong destination?!?

The full contents of the message body was: body: '{"id": "76e0fc3b-3ae0-4603-9099-3cd6bb15ffa9", "task": "celery.tasks.add", "args": ["2501"]}' (105b)
{content_type:None content_encoding:None
  delivery_info:{'redelivered': False, 'delivery_tag': 2, 'routing_key': 'celery', 'exchange': '', 'consumer_tag': 'None4'} headers={}}
</code></pre>

<p>So the task is not run, because the format is somewhat wrong.
I followed:
<a href="http://docs.celeryproject.org/en/latest/internals/protocol.html" rel="nofollow noreferrer">http://docs.celeryproject.org/en/latest/internals/protocol.html</a></p>

<p>The task is declared in <code>tasks.py</code> like this:</p>

<pre><code>from celery import Celery

app = Celery('tasks')
app.config_from_object('celeryconfig')


@app.task
def add(materialId):
    f = open('logg','w')
    f.write('processing task: ' + materialId)
    f.close()
</code></pre>

<p>So I'm not sure what should be corrected.
Could you help me on this?</p>

<p>If it's not possible I will fall back to invoking python
process from java but this will complicate the deployment process
so I would like to avoid it.</p>

<p><strong>Edit:</strong></p>

<p>To test my method I tried to schedule task this way from python also, but the error is the same:</p>

<pre><code>import pika

connection = pika.BlockingConnection(pika.ConnectionParameters('localhost'))
channel = connection.channel()
channel.queue_declare(queue='celery', durable=True)
channel.basic_publish(exchange='celery', routing_key='celery', body='{"id": "7421864e-aff3-4f2f-b274-9d5eacfc8941", "task": "celery.tasks.add", "args": ["2501"]}')
</code></pre>

<p><strong>Edit2</strong>:</p>

<p>This is not a duplicate of <a href="https://stackoverflow.com/questions/6933833/interoperating-with-django-celery-from-java">Interoperating with Django/Celery From Java</a>
since the answer does not solve my problem: adjusting routing key and exchange did not solve the problem.</p>