A simple library to connect to ihub and consume the messages.
Example:
import { IhubConnection, IhubEvent } from "ihub-connect";
const accessKey = "your-secret-access-key";
const consume = async () => {
const conn = await IhubConnection.connectToIhub(accessKey);
const consumer = await conn.createConsumer("shopify");
consumer.subscribe([IhubEvent.PRODUCT_ANY]);
consumer.listen(
(msg) => {
// do something with the message
},
{
ack: false, // whether or not to ack msg
}
);
};
consume();
You can also create multiple consumers:
const consumer = await conn.createConsumer("shopify");
consumer.subscribe([IhubEvent.PRODUCT_ANY]);
const consumer2 = await conn.createConsumer("shopify2");
consumer2.subscribe([IhubEvent.ORDER_CREATED]);
consumer.listen(
(msg) => {
// do something with the message
},
{
ack: false, // whether or not to ack msg
}
);
consumer2.listen(
(msg) => {
// do something with the message
},
{
ack: true, // whether or not to ack msg
}
);