Skip to content

emqx 5.x plugin exhook message bridge rocketmq、rabbitmq、kafka、redis stream

Notifications You must be signed in to change notification settings

thousmile/go_emqx_exhook

Repository files navigation

Quick Start

Thanks to @JetBrains for providing Goland support

vim /etc/go_emqx_exhook/config.yaml

appName: go_emqx_exhook
port: 16565

# Rocketmq or Rabbitmq or Kafka or Redis
mqType: Rocketmq

# grpc server tls
tls:
  enable: true
  caFile: certs/ca/ca.crt
  certFile: certs/server/server.crt
  keyFile: certs/server/server.key

# emqx topic
bridgeRule:
  topics:
    - "/#"

# rocketmq configuration, you need to create a topic in advance
rocketmqConfig:
  nameServer:
    - 192.168.0.188:9876
  topic: emqx_exhook
  tag: exhook
  groupName: exhook
  #accessKey: exhook
  #secretKey: exhook


# rabbitmq configuration, you need to create a switch in advance and bind a queue
rabbitmqConfig:
  addresses:
    - amqp:https://rabbit:[email protected]:5672
  exchangeName: emqx_exhook
  routingKeys: exhook
#  tls:
#    enable: true
#    tlsSkipVerify: true
#    caFile: /apps/server.cer.pem
#    certFile: /apps/client.cer.pem
#    keyFile: /apps/client.key.pem


# kafka configuration, you need to create a topic in advance
kafkaConfig:
  addresses:
    - 192.168.0.188:9092
  topic: emqx_exhook
#  sasl:
#    enable: true
#    user: admin
#    password: admin123456
#  tls:
#    enable: true
#    tlsSkipVerify: true
#    caFile: /apps/server.cer.pem
#    certFile: /apps/client.cer.pem
#    keyFile: /apps/client.key.pem


# redis configuration
redisConfig:
  addresses:
    - 127.0.0.1:6379
  streamName: emqx_exhook
  db: 0
#  username: redis123
#  password: redis123456
#  masterName: mymaster
#  sentinelUsername: sentinel123456
#  sentinelPassword: sentinel123456


# message send method "queue or direct", default: queue
# queue: after receiving the message, enter the queue and send it in batch when the queue conditions are met.
# direct: send immediately after receiving the message
# info: Rabbitmq and Redis do not support queue
sendMethod: queue


# queue configuration batchSize and lingerTime only satisfy one of them
queue:
  # when the number of messages in the queue reaches 100, batch send
  batchSize: 100
  workers: 2
  # after receiving the message, regardless of whether the number of messages in the queue is satisfied, it will be sent within 1 second.
  lingerTime: 1

grpc server support tls append to /etc/go_emqx_exhook/config.yaml

appName: go_emqx_exhook
port: 16565
# grpc server tls
tls:
  enable: true
  caFile: certs/ca/ca.crt
  certFile: certs/server/server.crt
  keyFile: certs/server/server.key

Emqx > ExHook > URL: Must start with https for example : https://127.0.0.1:16565

docker run -d --name go_emqx_exhook -p 16565:16565 \
  -v /etc/go_emqx_exhook/config.yaml:/apps/config.yaml \
  -v /etc/localtime:/etc/localtime:ro \
  --restart=always thousmile/go_emqx_exhook:1.8

vim docker-compose.yml

version: '3'

networks:
  app-net1:
    ipam:
      config:
        - subnet: 172.19.0.0/16
          gateway: 172.19.0.1

services:
  go_emqx_exhook:
    image: thousmile/go_emqx_exhook:1.8
    container_name: go_emqx_exhook
    ports:
      - "16565:16565"
    volumes:
      - /etc/go_emqx_exhook/config.yaml:/apps/config.yaml
      - /etc/localtime:/etc/localtime:ro
    privileged: true
    restart: always
    networks:
      app-net1:
    deploy:
      resources:
        limits:
          memory: 258m
docker compose up -d go_emqx_exhook

binary

download binary file after decompression, create a new config.yaml configuration file in the same directory as the binary file

EMQX Dashboard > ExHook

based on this project

# proto generate golang code
protoc --go_out=. --go-grpc_out=. proto/*.proto


# package binary
goreleaser --snapshot --skip-publish --clean
goreleaser release --skip=publish --clean

# build docker image
docker build -t go_emqx_exhook:1.8 ./


# run docker container
docker run -d --name go_emqx_exhook -p 16565:16565 --restart=always go_emqx_exhook:1.8


## custom configuration file
docker run -d --name go_emqx_exhook -p 16565:16565 \
  -v /etc/go_emqx_exhook/config.yaml:/apps/config.yaml \ 
  -v /etc/localtime:/etc/localtime:ro \ 
  --restart=always thousmile/go_emqx_exhook:1.8

consumer get mqtt attributes or Header

attributes name description
sourceId mqtt message Id
sourceTopic mqtt topic
sourceNode emqx node name
sourceFrom emqx from mqtt client id
sourceQos mqtt qos
sourceTimestamp message timestamp
protocol message protocol
peerhost producer ip

Redis:

Rabbitmq:

Kafka:

kafka-generate-ssl-automatic.sh

jks convert pem

keytool -importkeystore -srckeystore kafka.truststore.jks -destkeystore server.p12 -deststoretype PKCS12

openssl pkcs12 -in server.p12 -nokeys -out server.cer.pem

keytool -importkeystore -srckeystore kafka.keystore.jks -destkeystore client.p12 -deststoretype PKCS12

openssl pkcs12 -in client.p12 -nokeys -out client.cer.pem

openssl pkcs12 -in client.p12 -nodes -nocerts -out client.key.pem

About

emqx 5.x plugin exhook message bridge rocketmq、rabbitmq、kafka、redis stream

Resources

Stars

Watchers

Forks

Packages

No packages published