Module CSC7321—CSN: Middleware and software architecture for Internet distributed applications

Portail informatique

RabbitMQ Lab 1 — Home work

Questions after the discovery lab of RabbitMQ

Answer to the following questions by parsing the tutorial and searching the Web of RabbitMQ.

When you have an initial draft of an answer, check by yourself with the "elements of responses"/"Besoin d'aide ?". Do not hesitate to ask for other explanations.

What is the effect of the execution of the two following statements?

channel.queueDeclare(QUEUE_NAME, false, false, false, null);
channel.queueDeclare(QUEUE_NAME, false, false, false, null);

Declaring a queue is idempotent —it will only be created if it doesn't exist already.

What is the type of the content of a message?

The message content is a byte array, so you can encode whatever you like there.

What is the semantics of an acknowledgement?

In order to make sure a message is never lost, RabbitMQ supports message acknowledgments. An acknowledgement is sent back from the consumer to tell RabbitMQ that a particular message has been received, and that RabbitMQ is free to delete it.

If a consumer dies (its channel is closed, connection is closed, or TCP connection is lost) without sending an ack, RabbitMQ will understand that a message wasn't delivered and will re-queue it. If there are other consumers online at the same time, it will then quickly redeliver it to another consumer. That way you can be sure that no message is lost, even if the workers occasionally die.

What is the semantics of the assignement autoAck=false ?

Send a proper acknowledgment from the worker, once we're done with a task.

How to make the sending of messages reliable, including when the broker fails?

When RabbitMQ quits or crashes it will forget the queues and messages unless you tell it not to. Two things are required to make sure that messages aren't lost: we need to mark both the queue and messages as durable.

Marking messages as persistent doesn't fully guarantee that a message won't be lost. Although it tells RabbitMQ to save the message to disk, there is still a short time window when RabbitMQ has accepted a message and hasn't saved it yet. Also, RabbitMQ doesn't do fsync(2) for every message—it may be just saved to cache and not really written to the disk. The persistence guarantees aren't strong, but it's more than enough in many situations. If you need a stronger guarantee then you can use publisher confirms. See the page "Consumer Acknowledgements and Publisher Confirms". The following figure depicts in a continuum the reliability capabilities provided by RabbitMQ.

Continuum of the reliability capabilities provided by RabbitMQ

What is the semantics of the following two lines?

int prefetchCount = 1;
channel.basicQos(prefetchCount);

This tells RabbitMQ not to give more than one message to a worker at a time. Or, in other words, don't dispatch a new message to a worker until it has processed and acknowledged the previous one. Instead, it can dispatch it to the next worker that is not still busy.

What are the (four value) properties of the queue created with the following instruction?

String queueName = channel.queueDeclare().getQueue();

We create a "non-durable", "exclusive", "autodelete" queue with a "generated name".

What happpens if one publishes to an exchange that has no queues bound to it?

The messages will be lost if no queue is bound to the exchange yet.

Is it legal to have several queues bound to the same exchange with the same binding key?

It is perfectly legal to bind multiple queues with the same binding key. In Step 4 of the tutorial, we could add a binding between X and Q1 with binding key black. In that case, the direct exchange will behave like fanout and will broadcast the message to all the matching queues. A message with routing key black will be delivered to both Q1 and Q2.

What is the maximum size of a routing key?

There can be as many words in the routing key as you like, up to the limit of 255 bytes.

What are the two meta-characters of a binding key? Which semantics?

There are two important special cases for binding keys:
  • * (star): can substitute for exactly one word;
  • # (hash): can substitute for zero or more words.

How does one simulates an exchange of type fanout or of type direct with an exchange of type topic?

  • When a queue is bound with "#" (hash) binding key—it will receive all the messages, regardless of the routing key—like in fanout exchange.
  • When special characters "*" (star) and "#" (hash) aren't used in bindings, the topic exchange will behave just like a direct one.

How does one specify that the content is of type JSON?

The AMQP 0-9-1 protocol predefines a set of 14 properties that go with a message. Property "contentType" is used to describe the mime-type of the encoding.
For example for the often used JSON encoding it is a good practice to set this property to "application/json".

What is the semantics of the property correlationId of a message?

Property correlationId is used in Step 6 of the tutorial. It is useful to correlate RPC responses with requests. We're going to set it to a unique value for every request. Later, when we receive a message in the callback queue we'll look at this property, and based on that we'll be able to match a response with a request. If we see an unknown "correlationId" value, we may safely discard the message—it is not a reply to one of our requests. Usually, the server extracts the value inserted in the request and uses it for the answer.

What is the role of the JAVA class BlockingQueue? and the JAVA class ArrayBlockingQueue?

These two classes are used in Step 6 of the tutorial:

 

 

 


$Date: 2019-10-07 07:56:49 +0200 (lun. 07 oct. 2019) $