Client Library
Last updated
Was this helpful?
Last updated
Was this helpful?
CrimsonQ has an official Nodejs library at the moment and the rest are being developed. The current contribution team will provide client libraries for NodeJS + Typescript, Go and Python and would be happy to receive some community support on other libraries. Read the Advanced section on how to create a library based off of any Redis client, it is straight forward and we would appreciate the support.
The client library for both Nodejs and Typescript can be found here at the .
To get started with using it all you need to do is install it
Once you have installed the module you can then require it to use it in your code, whether as a producer or consumer you need to require it as follows; let CrimsonQ = require("./lib/crimsonq");
Once required you will need to setup the connection as follows;
To use the client as a Producer all you need to do is create a new producer for the client instance as follows;
producer.pushToConsumer(consumerId, message)
Send messages to a consumer's queue directly into its queue and will be in the pending state awaiting to be pulled.
consumerId
string
The consumer Id that will receive the message
message
Object
The message object that needs to be pushed to consumers
producer.pushToTopic
(topic, message) Send message to the topic queue and this will provide a message copy for each consumer in its queue.
topic
string
The topic that will be used to send to consumers listening to the topic. The topic can have MQTT style wildcards.
message
Object
The message object that needs to be pushed to consumers
The consumer will read messages out of its own queue, all the messages that have been sent to the consumer will be accessible through the consumer part of the library. To get started you will need to setup the consumer as follows;
You can setup the consumer by creating an instance and giving it a unique ID, make sure that each consumer you have has a different ID, if you need 2 consumers to read the same messages, create the consumer twice with different IDs but same topics, then push a message to a topic that matches both consumers.
Once you have gotten the consumer setup now its a matter of waiting for messages
This client is based on ioredis and has the same methodology, if a connection is interrupted it will reconnect and also be up and functional. The client will also start to pull the messages that the client missed when was online.
This is currently under development
This is currently under development
Then you can use the producer to publish messages. There are 2 ways you can publish messages, either directly to a consumer on its id, or to multiple consumers through a MQTT like topics, Below are the commands that can be used against the producer.
Kind: instance method of
Kind
: instance method of