Gulshan Jangid
Gulshan Jangid

Reputation: 481

how to send message from django server to a nodejs server and receive the reply?

Actually on the django server I have my website server running and on the nodejs server there is a bot which is running. I want my website to communicate with the bot forth and back. How can I achieve this? (for example: my bot accepts a trade given a list of items match to that trade and my website provides that list. So when I click a button my website will send the list to the bot and the bot will operate using that list)

Upvotes: 1

Views: 737

Answers (1)

comalex3
comalex3

Reputation: 2606

You can use http and websockets like @avril-lavigne said but for me best way to use Message queue (MQ) for example https://redis.io since it has pub\sub implememtation or maybe best for you zeromq.

  1. Easiest way: Send list of items to nodeJs server from the web page, process data and send result to webserver using websockets/long polling or just hit server every n second while data not ready and send back to user same way.
  2. Good way(for me) make api by Node js, communicate with nodeJs by RestApi(idea exactly like in 3th approach by use http).
  3. Hard way: In django you need create a task(your items with uniq id to indentify) to put the task to any storage (redis, your DB), send that task_id to web_page.

    In that time in nodeJs make a waiter which will wait for the task, process the data and put to storage.

    So you have task_id in browser client and ready data in storage. Now doing exactly same like in step 1 - hit every n second/* server to check if the task is complicated.

Upvotes: 2

Related Questions