public virtual void Init() { _logger.Info("public virtual void Init(): called"); // Create a connection to the broker. IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(DEFAULT_URI); _connection = new AMQConnection(connectionInfo); _logger.Info("Starting..."); // Register this to listen for exceptions on the test connection. _exceptionDelegate = new ExceptionListenerDelegate(OnException); _connection.ExceptionListener += _exceptionDelegate; // Establish a session on the broker. _channel = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1); // Create a durable, non-temporary, non-exclusive queue. _queueName = _channel.GenerateUniqueName(); _channel.DeclareQueue(_queueName, true, false, false); _channel.Bind(_queueName, ExchangeNameDefaults.TOPIC, _routingKey); // Clear the most recent message and exception. _lastException = null; }
public override void Init() { // Ensure that the base init method is called. It establishes a connection with the broker. base.Init(); connectionInfo = QpidConnectionInfo.FromUrl(connectionUri); _connection = new AMQConnection(connectionInfo); _channel = _connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 500, 300); _logger.Info("Starting..."); _logger.Info("Exchange name is '" + _exchangeName + "'..."); // Register this to listen for exceptions on the test connection. _exceptionDelegate = new ExceptionListenerDelegate(OnException); _connection.ExceptionListener += _exceptionDelegate; // Declare a new headers exchange with the name of the test service. _channel.DeclareExchange(_exchangeName, ExchangeClassConstants.HEADERS); // Create a non-durable, temporary (aka auto-delete), exclusive queue. string queueName = _channel.GenerateUniqueName(); _channel.DeclareQueue(queueName, false, true, true); // Bind the queue to the new headers exchange, setting up some header patterns for the exchange to match. _channel.Bind(queueName, _exchangeName, null, CreatePatternAsFieldTable()); // Create a test consumer to consume messages from the test exchange. _consumer = _channel.CreateConsumerBuilder(queueName) .WithPrefetchLow(100) .WithPrefetchHigh(500) .WithNoLocal(false) // make sure we get our own messages .Create(); // Register this to listen for messages on the consumer. _msgRecDelegate = new MessageReceivedDelegate(OnMessage); _consumer.OnMessage += _msgRecDelegate; // Clear the most recent message and exception. _lastException = null; _lastMessage = null; _publisher = _channel.CreatePublisherBuilder() .WithExchangeName(_exchangeName) .WithMandatory(true) .Create(); _publisher.DeliveryMode = DeliveryMode.NonPersistent; // Start all channel _connection.Start(); }