--- alias: user-guide-automation-task-core-rabbitMQ-subscribe-from-exchange tags: - automation tasks - rabbitMQ description: "This task creates a RabbitMQ subscription to a topic from a specified exchange, handling acknowledgements and potential errors" --- # RabbitMQ Subscribe from Exchange :iot-messagebus-listener-lg: The `RabbitMQ Subscribe from Exchange` task will create a subscription to a topic from a particular Exchange. If the request awaits for a reply it will create an execution context to acknowledge. This task is paired with the `RabbitMQ Acknowledge` task to return an acknowledge. ![Subscribe From Exchange Task](../images/rabbitmq_subscribefromexchange.png) ## Inputs | Name | Data Type | Description | |-----------------------|-----------|----------------------------------------------------------------------| | Exchange Name | `String` | The exchange Name to subscribe to. | | Exchange Type | `String` | The exchange type. | | Key | `String` | The topic key to subscribe to. | | Delete on unsubscribe | `String` | Should delete Exchange on unsubscribe. | | ReplyTimeout | `Integer` | Amount of time allowed to wait for a reply before issuing a timeout. | | Enable/Disable | `Boolean` | Activates or deactivates the subscription. Only needed when the `Auto Enable` setting is disabled; otherwise the task subscribes automatically once connected. | ## Outputs | Name | Data Type | Description | |------------|-----------|---------------------------------------------------------| | Topic | `String` | The topic received. | | rawMessage | `any` | The raw message received. | | message | `String` | The message content received. | | Success | `Boolean` | If there was no problem emits a true. | | Error | `Error` | Error that occurred during the processing of this task. | ## Settings | Name | Data Type | Default | Description | Values | |-----------------------|-----------|-------------------|-------------------------------------|------------| | Exchange Name | `String` | `defaultExchange` | The exchange Name to publish to. | | | Exchange Type | enum | `fanout` | The exchange type to use. | `direct`, `topic`, `headers`, `fanout`, `match` or`custom` | | Custom Exchange Type | `String` | | Custom Exchange type to use. Valid only when `custom` `Exchange Type` is selected. | | | Key | `String` | `defaultKey` | The topic key to publish to. | | | Auto Enable | `Boolean` | true | Automatically subscribe when the RabbitMQ connection is established. | | | Auto Ack | `Boolean` | true | Should an automatic acknowledge be sent upon receiving a message. | | | Delete on unsubscribe | `Boolean` | false | Should the exchange (and associated queue) be deleted on un-subscription. | | | Reply Timeout | `Integer` | 60000 | Amount of time allowed to wait for a reply before issuing a timeout. | | ## Behavior The `RabbitMQ Subscribe from Exchange` task creates a subscription to a topic from a particular Exchange and a context for each received message. If the request expects an acknowledge, the task waits for an execution from the `RabbitMQ Acknowledge` task within `ReplyTimeout`. When `Auto Enable` is set (the default), the task subscribes automatically as soon as the RabbitMQ connection is established, without needing the `Enable/Disable` input to be wired. If `Auto Enable` is disabled, the subscription is instead controlled by the `Enable/Disable` input: if set to `true` it subscribes, otherwise it unsubscribes, and the input must be wired to a triggering signal (for example, a controller-level enable flag) for the subscription to start. ## Remarks * This task allows the user to explicitly define the deletion of the exchange related with the subscription. This might be useful when exchange is only being used by this task, this way when the un-subscription occurs no durable exchanges stay on the rabbitMQ. * The user should be aware that no validation is done on the deletion procedure, this means that if there are any other subscriptions on this exchange they will be lost upon deletion.