I'm building a NodeJS with ZeroMQ Socket as publisher inside a Docker Container, and also a subscriber, but the subscriber is running in the laptop / host / localhost, don't really know how to name it.
Basically what I want to do is call to an endpoint /getData through postman, this endpoint is in the Node inside the Docker.
/getData endpoint basically will publish a message
Node from local should listen that message as it's subscribed (but this is where the it's failing, as it's not listening to the correct IP I guess, tried many IP directions and still not working)
I tried without setting a bridge, and it didn't work... setting a bridge didn't work either, buit I don't know if setting a bridge is the solution to be honest.
How could I approach this issue? I'm a bit lost about Docker ports / network
Node inside Docker:
import express, { Express, Request, Response } from 'express';import dotenv from 'dotenv';const zmq = require('zeromq');dotenv.config();const app: Express = express();const port = process.env.PORT || 3000;const sock = new zmq.Publisher();app.get('/getData', async (_req, res) => { await sock.send(['kitty cats', 'meow!']); res.status(200).json({ Status: 'Message Sent' });});app.listen(port, async () => { console.log(`[server]: Server is running at http://localhost:${port}`); await sock.bind('tcp://0.0.0.0:3500'); console.log('Publisher bound to port 3500');});
Node from local:
const express = require('express');const zmq = require('zeromq');const app = express();const port = 4000;app.listen(port, async () => { console.log(`Second backend server running on port ${port}`); const sock = new zmq.Subscriber(); sock.connect('tcp://backend-publisher:3500'); sock.subscribe('kitty cats'); console.log('Subscriber connected to port 3500'); for await (const [topic, msg] of sock) { console.log('received a message related to:', topic,'containing message:', msg ); }});
docker-compose.yml
version: '2'services: backend-publisher: build: . ports: - '3000:3000' - '3500:3500' - '5555:5555' networks: - zmq-networknetworks: zmq-network: driver: bridge