Skip to main content

message queue

Luwak sends messages as a producer. The following is the usage in JavaScript

luwak.sendMessage('Business topic', 'Business ID', 'Business additional data');

Example

Configure message queue

Configure connections such as RabbitMQ, Kafka

[
{
"mq_name": "rabbitmq",
"mq_type": "rabbitmq",
"mq_options": "{\"url\": \"amqp://guest:guest@localhost:5672/\", \"publish\": {\"exchange\": \"\", \"immediate \": false, \"mandatory\": false, \"routingKey\": \"hello\", \"contentType\": \"application/json\"}, \"timeout\": 5, \" queueDeclare\": {\"args\": null, \"name\": \"hello\", \"noWait\": false, \"durable\": false, \"exclusive\": false, \ "autoDelete\": false}}",
"is_enabled": 1,
"description": null
},
{
"mq_name": "kafka",
"mq_type": "kafka",
"mq_options": "{\"addressList\": [\"localhost:29092\"]}",
"is_enabled": 1,
"description": null
}
]

Define topics and associate topics to connections

[
{
"mq_name": "rabbitmq",
"topic_name": "hrm.salary.processed",
"description": "Complete employee salary payment"
},
{
"mq_name": "kafka",
"topic_name": "hrm.payroll.processed",
"description": "Salary processing completed"
}
]

Send message in Post Action

luwak.sendMessage("hrm.employee.created", 101, {id: 101, name: "Lillian Haddadi"});

luwak.sendMessage("hrm.payroll.processed", 101, {id: 101, name: "Lillian Haddadi"});

What Luwak actually sent

RabbitMq

{
"mqName": "rabbitmq",
"messageId": "cmchbbvctdnitv88prkg",
"createdAt": "2024-01-06 16:56:15.955",
"topicName": "hrm.employee.created",
"bizId": 101,
"bizData": {
"id": 101,
"name": "Lillian Haddadi"
}
}

Kafka

{
"mqName": "kafka",
"messageId": "cmchbbvctdnitv88prl0",
"createdAt": "2024-01-06 16:56:15.959",
"topicName": "hrm.payroll.processed",
"bizId": 101,
"bizData": {
"id": 101,
"name": "Lillian Haddadi"
}
}