Setting up a result backend (rpc) with Celery in Django
<p>I am attempting to get a result backend working on my local machine for a project I'm working on but I am running into an issue.</p>

<p>Currently I am trying to create a queue system in order for my lab to create cases. This is to prevent duplicate sequence numbers from being used. I am already using Celery for our printing so I figured I would create a new Celery queue and use that to handle the case. The front-end also needs to get the results of the case creations to display the case number that was created.</p>

<p><a href="http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html#rabbitmq" rel="nofollow">http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html#rabbitmq</a></p>

<p>I was following the above tutorial on getting my Celery configured. Below is the source:</p>

<p>celeryconfig.py:</p>

<pre><code>from kombu import Queue
CELERY_DEFAULT_QUEUE = 'celery'
CELERY_DEFAULT_EXCHANGE = 'celery'
CELERY_DEFAULT_EXCHANGE_TYPE = 'direct'
CELERY_RESULT_BACKEND = 'rpc://'
CELERY_RESULT_PERSISTENT = False

CELERY_QUEUES = (
    Queue('celery',    routing_key="celery"),
    Queue('case_creation',       routing_key='create.#')
)

CELERY_ROUTES = {
    'case.tasks.create_case': {
        'queue': 'case_creation',
        'routing_key': 'create.1'
    },
    'print.tasks.connect_and_serve': {
        'queue': 'celery',
        'routing_key': 'celery'
    }
}
</code></pre>

<p>celery.py:</p>

<pre><code>import os

from celery import Celery

from django.conf import settings
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'proj.settings.local')

app = Celery('proj', broker='amqp://guest@localhost//')

app.config_from_object('proj.celeryconfig')
app.autodiscover_tasks(lambda: settings.INSTALLED_APPS)
</code></pre>

<p>tasks.py:</p>

<pre><code>import celery
from django.db import IntegrityError

from case.case_create import CaseCreate


@celery.task(bind=True)
def create_case(self, data, user, ip):
    try:
        acc = CaseCreate(data, user, ip)
        return acc.begin()
    except IntegrityError as e:
        self.retry(exc=e, countdown=2)
</code></pre>

<p>Here is my view that calls the above task:</p>

<pre><code>@require_authentication()
@requires_api_signature()
@csrf_exempt
@require_http_methods(['POST'])
def api_create_case(request):
    result = create_case.delay(json.loads(request.body.decode('utf-8')), request.user, get_ip_address(request))
    print(str(result))  # Prints the Task ID
    print(str(result.get(timeout=1)))  # Throws error
    return HttpResponse(json.dumps({'result': str(result)}), status=200)
</code></pre>

<p>I start my celery queue with the following command:</p>

<pre><code>celery -A proj worker -Q case_creation -n case_worker -c 1
</code></pre>

<p>When I run the celery worker I do see results show up under config:</p>

<pre><code> -------------- celery@case_worker v3.1.16 (Cipater)
---- **** -----
--- * ***  * -- Windows-8-6.2.9200
-- * - **** ---
- ** ---------- [config]
- ** ---------- .&gt; app:         proj:0x32a2990
- ** ---------- .&gt; transport:   amqp://guest:**@localhost:5672//
- ** ---------- .&gt; results:     rpc://
- *** --- * --- .&gt; concurrency: 1 (prefork)
-- ******* ----
--- ***** ----- [queues]
 -------------- .&gt; case_creation    exchange=celery(direct) key=create.#
</code></pre>

<p>When I run the program and submit a new case this is the error message that I get:</p>

<pre><code>No result backend configured.  Please see the documentation for more information.
</code></pre>

<p>I have attempted every single thing I can find online. Is there anyone out there that can point me in the right direction? I'm so very close and so very tired of looking at this code.</p>

<p>If you want to keep your result, try this <a href="http://docs.celeryproject.org/en/latest/getting-started/first-steps-with-celery.html#keeping-results" rel="nofollow">Keeping Results</a></p>

<pre><code>app = Celery('proj', backend='amqp', broker='amqp://guest@localhost//')
</code></pre>

<h3>EDIT</h3>

<blockquote>
  <p>Make sure the client is configured with the right backend.</p>
  
  <p>If for some reason the client is configured to use a different backend than the worker, you will not be able to receive the result, so make sure the backend is correct by inspecting it:</p>
</blockquote>

<p>Try this to see the output:</p>

<pre><code>&gt;&gt;&gt; result = task.delay(â¦)
&gt;&gt;&gt; print(result.backend)
</code></pre>

<p>other solutions will be instead of </p>

<pre><code>app = Celery('proj',
         backend='amqp',
         broker='amqp://',
         include=['proj.tasks'])
</code></pre>

<p>Try:</p>

<pre><code>app = Celery('proj',
             broker='amqp://',
             include=['proj.tasks'])
app.conf.update(
    CELERY_RESULT_BACKEND='amqp'
)
</code></pre>

python django celery