I've taken the Dapr pub/sub How-to sample and tried to update it to use RabbitMQ
I've downloaded the Docker rabbitmq:3 image from DockerHub and it should be listening on amqp://localhost:5672.
I have created a new component file for RabbitMQ called rabbitmq.yaml and placed it in the .dapr/components directory. My component configuration for RabbitMQ is:
apiVersion: dapr.io/v1alpha1
kind: Component
metadata:
name: my-rabbitmq
spec:
type: pubsub.rabbitmq
version: v1
metadata:
- name: host
value: amqp://localhost:5672
- name: durable
value: true # Optional. Default: "false"
- name: deletedWhenUnused
value: false # Optional. Default: "false"
- name: ttlInSeconds
value: 60
- name: prefetchCount
value: 0
My subscription is defined in subscription-rabbitmq.yaml located in the same .dapr/components directory. and it looks as follows:
apiVersion: dapr.io/v1alpha1
kind: Subscription
metadata:
name: rabbitmq-subscription
spec:
topic: deathStarStatus
route: /dsstatus
pubsubname: my-rabbitmq
scopes:
- app2
When I run the sample using the Redis Streams component and subscription, the node application receives the message and displays in within the output of the dapr run command.
dapr publish --topic deathStarStatus --pubsub pubsub --data '{ "message": "This is a test" }'
but when I publish a message to RabbitMQ, it states the "Event Published Successfully", but the node app doesn't receive the message.
dapr publish --topic deathStarStatus --pubsub my-rabbitmq --data '{ "message": "This is a test" }'
Here is the node app and the command to run it:
dapr run --app-id app2 --app-port 3000 node app2.js
const express = require('express')
const bodyParser = require('body-parser')
const app = express()
app.use(bodyParser.json({ type: 'application/*+json' }));
const port = 3000
// app.get('/dapr/subscribe', (req, res) => {
// res.json([
// {
// pubsubname: "my-rabbitmq",
// topic: "deathStarStatus",
// route: "dsstatus"
// }
// ]);
// })
app.post('/dsstatus', (req, res) => {
console.log(req.body);
res.sendStatus(200);
});
app.listen(port, () => console.log(`consumer app listening on port ${port}!`))
What am I doing wrong?
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…