Interface RabbitMQConnection

All Known Implementing Classes:
RabbitMQConnectionImpl

public interface RabbitMQConnection
Represents a managed RabbitMQ connection with channel pooling support.

Connections are configured via .properties files referenced by the CONNECTOR_RABBITMQ_<ID>_CONFIG environment variable. Supported properties:

  • host — broker hostname (default: localhost)
  • port — broker port (default: 5672)
  • username — authentication username (default: guest)
  • password — authentication password (default: guest)
  • virtualHost — virtual host (default: /)
  • ssl — enable SSL with default JVM SSLContext (default: false)
  • channelPoolSize — fixed channel pool size (default: 5)

Channels are managed through a fixed-size pool. Use borrowChannel() to obtain a PooledChannel that automatically returns to the pool when closed:


 try (var channel = connection.borrowChannel()) {
     channel.basicPublish("exchange", "key", null, "message".getBytes());
 }
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Borrows a channel from the fixed-size pool.
    Returns the underlying RabbitMQ connection.
    void
    Initializes the RabbitMQ connection and pre-creates the channel pool.
    boolean
    Returns whether this connection is configured to cause server shutdown on initialization failure.
    void
    Shuts down the connection, closing all pooled channels and the underlying connection.
  • Method Details

    • getConnection

      @NotNull Connection getConnection()
      Returns the underlying RabbitMQ connection.
      Returns:
      the raw Connection instance
      Throws:
      NullPointerException - if called before init()
    • borrowChannel

      Borrows a channel from the fixed-size pool.

      The returned PooledChannel implements AutoCloseable and should be used in a try-with-resources block to ensure the channel is returned to the pool.

      Returns:
      a pooled channel wrapper
      Throws:
      InterruptedException - if the current thread is interrupted while waiting for a channel
    • init

      void init() throws ConnectionInitException
      Initializes the RabbitMQ connection and pre-creates the channel pool.
      Throws:
      ConnectionInitException - if the connection or channel pool creation fails
    • shutdown

      void shutdown()
      Shuts down the connection, closing all pooled channels and the underlying connection.
    • isExitOnFailure

      boolean isExitOnFailure()
      Returns whether this connection is configured to cause server shutdown on initialization failure.
      Returns:
      true if the server should exit when this connection fails to initialize