Message queues vs sockets
Asked Answered
S

2

51

I don't have much of a socket programming experience but I tried read a little about it. I am quite familiar with MDB and messaging queues. Someone has told me that queue(e.g. MDB) is "Not much more than a direct socket connection". Can someone compare these two for me.

Stanfordstang answered 19/5, 2012 at 18:59 Comment(0)
G
90

The two are incomparable, as they represent different layers. It's like comparing a relational database to a file on a disk or comparing a house to a brick (i.e. certainly you need files to build databases and bricks to build houses, and sometimes all you need is a file or a brick, but that does not make them comparable).

Messaging queue is a piece of software that glues senders and receivers so that they can communicate without knowing much about each other (they both need to know about the queue, of course) and do not need to implement networking code, handling failure, routing one message to many receivers etc. The system works even if senders and receivers are never alive at the same time, as queues also serve as a temporary storage for undelivered messages. Aside from that, queues can provide additional services, like authorization, transactions etc.

A socket connection is a low-level network abstraction that says: "currently two programs can send data over a network to each other, at least until connection breaks for some reason". So yes, usually a messaging queue will use a socket connection to work across a network.

By the way: MDB (Message Driven Bean) that you mention is not a message queue (just like JDBC isn't a databasae). It's an API for consuming transactional messages. They may come from a queue, but they don't have to.

Geanticline answered 19/5, 2012 at 19:16 Comment(3)
Oh Okay thanks. So when someone actually uses only socket to transfer data, they just make things more manual and complicated for themselves? I mean Messaging queues just comes on top of that to make things easier for us. Like a database on top of pure file. I think that person might have meant that there are not much of a feature added which you can't implement using sockets themselves & code them manually. Thanks anyways for the clarification.Stanfordstang
So here is his answer to my above question: " We can implement messaging using a simple socket connection. The advantages and disadvantages: Socket level coding is likely more compact and based on our needs. However, it requires the developer to manage capabilities already available in many packages. The choice is decision based on many factors (time, cost, talent, future talent)"Stanfordstang
The answer is certainly true but also quite generic. It also encompasses things like rolling out your own http servers, databases, operating systems and so on. Replacing such mature products with home-brew is probably only realistic in cases when you have very specific and at the same time very limited requirements (like when you have a queue that has to be incredibly fast and compact, but does not need to be reliable or secure).Geanticline
M
8

The two are totally different in the sense that;

  1. Socket allows connection between clients who know themselves whiles (eg between a client and a backend service or between backend services).

  2. Message queue mostly acts as an interface between different backend services in a message-driven system. The services don't need to know whom they are communicating with except the Message broker (eg, rabbitMQ, activeMQ, Kafka). This makes sure that messages are not lost even if one of the services is down. Immediately the service comes up, the Message broker sends the message to the consumer.

Mccomb answered 29/1, 2021 at 18:59 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.