Message queues vs sockets

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.

Leave a Comment