HomePhabricator
Diffusion Comm 96e4dd08c898

[services] Tunnelbroker - Put and get messages from database in grpc handler

Description

[services] Tunnelbroker - Put and get messages from database in grpc handler

Summary:
Message persisting logic in this diff:

  • On gRPC Send request we are storing a message to the dynamoDB database before the AMQP message is pushed to the RabbitMQ. In this case, we are making sure that the message is persisted and we don't rely on the RabbitMQ delivery only.
  • On gRPC Get request, we are retrieving the messages for the deviceID from the dynamoDB database first and delivering them to the device.
    • After retrieving messages from the database, wait for the messages from the AMQP message broker (RabbitMQ);
    • Follow-up messages are delivered as Get stream request messages;
    • On message broker (RabbitMQ) message delivery, delete that message from the database by unique messageID.

Test Plan:

  1. Run yarn run-tunnelbroker-service and successfully built the service without any warnings and errors.
  2. Message successfully delivered when clients are online:
    • Client with deviceID#1 sends the message to deviceID#2 using the Send request;
    • deviceID#2 is online and listening for the new messages using the Get stream;
    • deviceID#2 instantly and successfully gets the message from deviceID#1 using the Get stream;
  3. Message successfully delivered after client reconnects/offline:
    • Client with deviceID#1 sends the message to deviceID#2 using the Send request;
    • deviceID#2 is offline at that time;
    • deviceID#2 connects to the tunnelbroker server and successfully gets the message from deviceID#1 using the Get stream;
  4. Message successfully delivered when RabbitMQ server was restarted and the queue was cleared when the messages were sent, but the device was offline at that time and then reconnects after:
    • Client with deviceID#1 sends the message to deviceID#2 using the Send request;
    • deviceID#2 is offline at that time;
    • RabbitMQ server goes down, the messages queue was cleared;
    • RabbitMQ server goes up;
    • deviceID#2 connects to the tunnelbroker server and successfully gets the message from deviceID#1 using the Get stream.

Reviewers: karol-bisztyga, palys-swm, ashoat

Reviewed By: karol-bisztyga, palys-swm, ashoat

Subscribers: ashoat, palys-swm, Adrian, atul, karol-bisztyga, yayabosh

Differential Revision: https://phabricator.ashoat.com/D3833