Clients -
rabbitmq :
Channel
The Ballerina interface to provide AMQP Channel related functionality.
Constructor
__init
(ConnectionConfiguration | Connection connectionOrConnectionConfig)
- connectionOrConnectionConfig ConnectionConfiguration | Connection
-
A
rabbitmq:Connection
object or a connection configuration
Remote Methods
queueDeclare | Declares a non-exclusive, auto-delete, or non-durable queue with the given configurations.
|
exchangeDeclare | Declares a non-auto-delete, non-durable exchange with no extra arguments. If the arguments are specified, then the exchange is declared accordingly.
|
queueBind | Binds a queue to an exchange with the given binding key.
|
basicPublish | Publishes a message. Publishing to a non-existent exchange will result in a channel-level protocol error, which closes the channel.
|
queueDelete | Deletes the queue with the given name although it is in use or has messages in it.
If the
|
exchangeDelete | Deletes the exchange with the given name.
|
queuePurge | Purges the content of the given queue.
|
basicGet | Retrieves a message synchronously from the given queue providing direct access to the messages in the queue.
|
Methods
Retrieves the connection, which carries this channel.
Closes the rabbitmq:Channel
.
Aborts the RabbitMQ rabbitmq:Channel
.
Declares a non-exclusive, auto-delete, or non-durable queue with the given configurations.
string|rabbitmq:Error? queueResult = newChannel->queueDeclare();
Parameters
- queueConfig QueueConfiguration? (default ())
-
Configurations required to declare a queue
-
Return Type
(string | Error | ()) The name of the queue if autogenerated,
()
if the queue was successfully generated with the given parameters, or else arabbitmq:Error
if an I/O error is encountered
Declares a non-auto-delete, non-durable exchange with no extra arguments. If the arguments are specified, then the exchange is declared accordingly.
rabbitmq:Error? exchangeResult = newChannel->exchangeDeclare({
exchangeName: "MyExchange",
exchangeType: rabbitmq:DIRECT_EXCHANGE,
durable: true,
autoDelete: true });
Parameters
- exchangeConfig ExchangeConfiguration
-
Configurations required to declare an exchange
-
Return Type
(Error?) A
rabbitmq:Error
if an I/O error is encountered or else()
Binds a queue to an exchange with the given binding key.
rabbitmq:Error? bindResult = newChannel.queueBind("MyQueue", "MyExchange", "routing-key");
Parameters
- queueName string
-
Name of the queue
- exchangeName string
-
Name of the exchange
- bindingKey string
-
Binding key used to bind the queue to the exchange
-
Return Type
(Error?) A
rabbitmq:Error
if an I/O error is encountered or else()
basicPublish
(MessageContent messageContent, string routingKey, string exchangeName, BasicProperties? properties)
returns Error?Publishes a message. Publishing to a non-existent exchange will result in a channel-level protocol error, which closes the channel.
rabbitmq:Error? sendResult = newChannel->basicPublish("Hello from Ballerina", "MyQueue");
Parameters
- messageContent MessageContent
-
The message body
- routingKey string
-
The routing key
- exchangeName string
-
The name of the exchange to which the message is published
- properties BasicProperties? (default ())
-
Other properties for the message (routing headers, etc.)
-
Return Type
(Error?) A
rabbitmq:Error
if an I/O error is encountered or else()
Deletes the queue with the given name although it is in use or has messages in it.
If the ifUnused
or ifEmpty
parameters are given, the queue is checked before deleting.
rabbitmq:Error? deleteResult = newChannel->queueDelete("MyQueue");
Parameters
- queueName string
-
Name of the queue to be deleted
- ifUnused boolean (default false)
-
True if the queue should be deleted only if it's not in use
- ifEmpty boolean (default false)
-
True if the queue should be deleted only if it's empty
-
Return Type
(Error?) A
rabbitmq:Error
if an I/O error is encountered or else()
Deletes the exchange with the given name.
rabbitmq:Error? deleteResult = newChannel->exchangeDelete("MyExchange");
Parameters
- exchangeName string
-
The name of the exchange
-
Return Type
(Error?) A
rabbitmq:Error
if an I/O error is encountered or else()
Purges the content of the given queue.
rabbitmq:Error? purgeResult = newChannel->queuePurge("MyQueue");
Parameters
- queueName string
-
The name of the queue
-
Return Type
(Error?) A
rabbitmq:Error
if an I/O error is encountered or else()
Retrieves a message synchronously from the given queue providing direct access to the messages in the queue.
rabbitmq:Message|rabbitmq:Error getResult = newChannel->basicGet("MyQueue", rabbitmq:AUTO_ACK);
Parameters
- queueName string
-
The name of the queue
- ackMode AcknowledgementMode
-
Type of the acknowledgement mode
Retrieves the connection, which carries this channel.
rabbitmq:Connection|rabbitmq:Error connResult = newChannel.getConnection();
-
Return Type
(Connection | Error) A
rabbitmq:Connection
object or else arabbitmq:Error
if an I/O error is encountered
Closes the rabbitmq:Channel
.
rabbitmq:Error? closeResult = newChannel.close();
Parameters
- closeCode int? (default ())
-
The close code (for information, go to the "Reply Codes" section in the [AMQP 0-9-1 specification] (#https://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf))
- closeMessage string? (default ())
-
A message indicating the reason for closing the channel
-
Return Type
(Error?) A
rabbitmq:Error
if an I/O error is encountered or else()
Aborts the RabbitMQ rabbitmq:Channel
. Forces the rabbitmq:Channel
to close and waits for all the close operations
to complete. Any encountered exceptions in the close operations are discarded silently.
rabbitmq:Error? abortResult = newChannel.abortChannel(320, "Channel Aborted");
Parameters
- closeCode int? (default ())
-
The close code (for information, go to the "Reply Codes" section in the [AMQP 0-9-1 specification] (#https://www.rabbitmq.com/resources/specs/amqp0-9-1.pdf))
- closeMessage string? (default ())
-
A message indicating the reason for closing the channel
-
Return Type
(Error?) A
rabbitmq:Error
if an I/O error is encountered or else()