Code Monkey home page Code Monkey logo

rabbitmqtutorials's Introduction

RabbitMQ Tutorials

The repository contains my code to .net tutorials from https://www.rabbitmq.com/getstarted.html.

Read my notes from tutorials.

Review

  • Who creates a queue - producer or consumer?

    They both declare the queue. Since declaring a queue is idempotent, it doesn't matter who does it first, as long as they both declare it with the same configuration.

  • What happens if they declare the queue with different configurations?

    The later one will simply fail and get an exception. For example, one party declared a queue with setting durable: false, now if the second party tries to declare the same queue with durable: true, they get an error: PRECONDITION_FAILED - inequivalent arg 'durable' for queue 'hello' in vhost '/': received 'true' but current is 'false'.

  • Producer sends messages to what? To queue, topic, exchange?

    Lets start from a consumer side: consumer consumes messages from a queue, period. So, effectively messages are delivered to a queue, but they are published to exchanges with a routing information in routing key, so you can say: a producer sends messages to an exchange.

  • What is an exchange and a routing key?

    An exchange is a hub for queues. It's compared to a post office or mailboxes, but I don't fancy this metaphor. It's a hub. You publish a message to an exchange. Exchanges are connected with queues, such connection is called a binding. The binding has a routing key and the message has a routing key, so when a message is published, Rabbit matches those routing keys to decide which queues should get a copy of the message.

  • Do I need to provide a routing key always?

    No, not always. It depends on the type of the exchange. There are four types of exchanges. The tutorials consider three: direct, fanout, and topic. With fanout exchange, the routing key is not used (ignored), because when a new message is published to a fanout exchange, a copy of the message is delivered to all queues bound with the exchange.

  • So how the routing key differ between direct and topic exchanges?

    With a direct exchange, a queue gets the message if their routing keys are equal. With a topic exchange, a routing key is a mask. For example, a message with a routing key set to quick.orange.rabbit will be delivered to queues with keys quick.# and *.*.rabbit.

  • So if the queues in a topic exchange have # key, it's like a fanout exchange?

    Yes.

  • And if I don't use # and * at all in the queues' keys in a topic exchange, it's like a direct exchange?

    Yes.

  • Ok, but do I always need to have a dedicated exchange, configure it and bind my queues with it?

    No. For the simplest scenarios you can skip the exchange declaration eg. channel.BasicPublish(exchange: "", routingKey: "myQueue", body: body). Here, the message will be delivered to a queue with name myQueue. Looks like there's no exchange used, but actually you have just used the default exchange.

  • What are publisher confirms?

    If you publish a message you're not 100% sure that the broker actually received the message. Mind, that we're not talking about consumer, just the broker. So if you want to be sure, that Rabbit handled the message, you need to use a confirmation mechanism. This confirmation is called an acknowledgement or ack, and nack for negative acknowledgement.

  • How do I do it?

    It's all in the benchmarked code of PublisherConfirms. In a nutshell, you either do it synchronously or asynchronously in the publisher. Synchronous mode with waiting for an ack after every message has a significant performance impact but is very easy to implement. On the other hand, asynchronous mode works quick but it requires more code. There's a middle ground, with doing the sync way but in batches.

rabbitmqtutorials's People

Contributors

foka avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.