Is it possible to change the IP address of a Javascript Paho MQTT client after Creating it? - client

I'm writing a web application in javascript where I want a single Paho.MQTT.Client to be able to disconnect from an MQTT broker, and connect it to another MQTT broker with a different IP address.
Is this possible?
Or do I have to delete my existing Paho.MQTT.Client and create a new one with a different IP address in order to switch between different MQTT brokers?
I've tried myClient._setHost("a.b.c.d"); and that returns 'Unsupported', even after a call to myClient.disconnect().

You have to create a new instance of the client to change which broker it is connected to once connect() has been called.
the _setHost() function is internal only (not listed as part of the public API) and should not be used.

Related

Multiple clients one TCP server select()

I'm a beginner to TCP client-server architecture. I am making a client-server application in C++ I need the server to be able to accept messages from multiple clients at once. I used this IBM example as my starter for the server
server.
The client side is irrelevant but this is my source client.
The problem is with the server side it allows multiple clients to connect but not asynchronously, so the server will connect with the second client after the first one finishes. I want the server to watch for messages from both clients.
I tried to read about select() on the Internet but I couldn't find anything to make the IBM code async. How can I edit the server code to allow the clients to connect and interact at the same time?

Is nest js microservices(EventPattern) the same as websockets?

I try to make a nest.js server, that publishes events, and it doesn't know his subscribers. As far as I concerned, microservices in nest.js works in the same way as websockets. But I've met some problems. Looks like all microservices must know about each other. So I can't make a microservice-server (server_A), that emits events and microservices-clients, that subscribes events of server_A.
Using websockets, it is possible. Is it possible to do it, using microservices?
I tryied to create microservice (server_A) on localhost, then I created a subscriber on localhost also. I made them work on localhost as expected. But when I try to deploy server_A on remote server, I can't connect my microservice-subscriber from localhost, even if I fill correct host and ip.
There is the error: Error: listen EADDRNOTAVAIL: address not available x.x.x.x:port (real ip is masked)
But I think, if I make server_A a websocket server, and then subscribe by another nest.js application, it will work no matter wherefrom will I connect

zeromq DEALER client to multiple servers (ROUTER)

I am using ZEROMQ for distributed messaging application. Need to connect client (DEALER socket) to multiple servers (ROUTER socket on server side). What are my options on CLIENT side ?
Create DEALER socket on client side for each server endpoint (ROUTER socket).
Create only ONE DEALER socket on client side and add multiple endpoints.
I tried option 2 - connecting to multiple endpoints but message always goes to the first connected endpoint. followed following steps:
create DEALER socket
connect to first endpoint
then at run time, add another endpoint to the socket by using socket.connect(endpoint).
Do I need to reconnect?
In DEALER socket, there is no option to send message on a particular endpoint in case it is connected to multiple endpoints.
Any idea?
ZeroMQ encodes certain behaviors into socket types. These mainly deal with:
handling multiple peers
handling undeliverable messages
handling excessive throughput (HWM)
A DEALER socket is one that can connect to multiple peers, and uses LRU (least recently used, aka round-robin) to decide which peer gets each message. If you do not want this behavior, then you do not want a DEALER socket with multiple peers.
If you want to decide which peer gets a message, there are two options for this:
create a DEALER per peer, and send on the appropriate socket
create a single ROUTER connected to all peers, and use IDENTITY prefixes to route messages. You may need to pass IDENTITIES via a side channel, in order to use ROUTER-ROUTER connections.
at run time, add another endpoint to the socket by using socket.connect(endpoint). Do I need to reconnect?
No, you do not need to reconnect. You can add (and remove) peers at any time during the program.

Are AMQP connections (RabbitMQ) between Cloundfoundry applications possible?

I have two applications deployed on Cloudfoundry: a service application that computes stuff (aka computeService) and a client application that renders html for us mortals to hit buttons on (aka clientService). I would like a controller in the clientService to send commands to the computeService (when mortals hit buttons). The broker and the computeService run on the same machine.
I know I cannot make remote AMQP connections into a service on cloudfoundry.com, but I assume I can make connections between applications. However, every sensible address combination for broker and clientService gives me the same error:
javax.jms.JMSException: Could not connect to broker URL: tcp://127.0.0.1:61616. Reason: java.net.ConnectException: Connection refused
Whatever address I try, I cannot post to the queue. The code works flawlessly on my local machine.
My question: can I use RabbitMQ to pass messages between the two applications on Cloudfoundry? And if so, which addresses should I use?
Thanx!
One way to try this out is to create two replicas of the rabbit message example at Spring Samples
...a message sender and a message receiver. When deployed, they should share the same rabbit service.
I pushed the rabbit message which worked for me to: rabbitmessage-sndrcv

Pulling requests from multiple clients with ZMQ

I have a couple of workers waiting to do some jobs. I see that in the PULL/PUSH pattern I need to give the workers the ip address (using the tcp protocol) of the client, so it can listen to requests from there. However, in my case I want to have a lot of clients as well, coming from different IPs with requests... So basically I dont really have a static IP to bind the worker to PULL from. Am I using the wrong pattern or is there a way to do it correctly?
You should consider using the router-dealer pattern. Your router binds at 2 ends and it has a static IP. It pulls from the multiple clients that connect to it and pushes to the workers on the other end. You can use the ROUTER/DEALER socket types to make this or just use an extra bridge using PUSH/PULL sockets to connect the clients to the workers.

Resources