In this article we discuss what happens when we set a transport connector to a broker service and start the broker service.
BrokerService broker = new BrokerService(); broker.setBrokerName("LocalBroker"); broker.setUseJmx(false); broker.setPersistent(false); broker.setTransportConnectorURIs(new String[]{"tcp://localhost:61616"}); broker.start();
A transport connector helps client to connect to a broker and communicate with it. There are many transport connectors available. Here we will base our discussion on Tcp scheme.
A serverSocket is created and continuously listens for a connection to be made to this socket.
When a client connects to a broker based on this connector, the server accepts it and a new socket is created.
The socket can be handled in the same thread or queued to be handled later in a separate thread.
Handling of socket deals with creating input/output streams. Server sends the broker info to the connected client.
A separate thread is created to read the input stream. The input stream read is converted into a command and consumed. After consuming the command, if we have any response, it is dispatched synchronously in the same thread.