/// <summary> /// Starts the interop test client running. This causes it to start listening for incoming test invites. /// </summary> private void Start() { log.Info("private void Start(): called"); // Use a class path scanner to find all the interop test case implementations. ArrayList testCaseClasses = new ArrayList(); // ClasspathScanner.getMatches(InteropClientTestCase.class, "^TestCase.*", true); // Hard code the test classes till the classpath scanner is fixed. testCaseClasses.Add(typeof(TestCase1DummyRun)); testCaseClasses.Add(typeof(TestCase2BasicP2P)); testCaseClasses.Add(typeof(TestCase3BasicPubSub)); testCaseClasses.Add(typeof(TestCase4P2PMessageSize)); testCaseClasses.Add(typeof(TestCase5PubSubMessageSize)); // Create all the test case implementations and index them by the test names. foreach (Type testClass in testCaseClasses) { InteropClientTestCase testCase = (InteropClientTestCase)Activator.CreateInstance(testClass); testCases.Add(testCase.GetName(), testCase); log.Info("Found test case: " + testClass); } // Open a connection to communicate with the coordinator on. log.Info("brokerUrl = " + brokerUrl); IConnection connection = CreateConnection(brokerUrl, virtualHost); channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge); // Set this up to listen for control messages. string responseQueueName = channel.GenerateUniqueName(); channel.DeclareQueue(responseQueueName, false, true, true); channel.Bind(responseQueueName, ExchangeNameDefaults.TOPIC, "iop.control." + clientName); channel.Bind(responseQueueName, ExchangeNameDefaults.TOPIC, "iop.control"); IMessageConsumer consumer = channel.CreateConsumerBuilder(responseQueueName) .Create(); consumer.OnMessage += new MessageReceivedDelegate(OnMessage); // Create a publisher to send replies with. publisherBuilder = channel.CreatePublisherBuilder() .WithExchangeName(ExchangeNameDefaults.DIRECT); // Start listening for incoming control messages. connection.Start(); Console.WriteLine("Test client " + clientName + " ready to receive test control messages..."); }
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(); }
public virtual void Setup() { Guard.NotNull(_channel, "Channel cannot be null"); Guard.NotNull(_interpreter, "Interpreter cannot be null"); _channel.SubscribeRawDataReceived(_interpreter.Interprete); _interpreter.AddMessageHandler(_messageHandler); _channel.Bind(); if (SetupFinished != null) { SetupFinished(); } }
/// <summary> /// Assigns the role to be played by this test case. The test parameters are fully specified in the /// assignment message. When this method return the test case will be ready to execute. /// </summary> /// /// <param name="role"> The role to be played; sender or receiver. </param> /// <param name="assignRoleMessage"> The role assingment message, contains the full test parameters. </param> public void AssignRole(Roles role, IMessage assignRoleMessage) { log.Debug("public void AssignRole(Roles role = " + role + ", Message assignRoleMessage = " + assignRoleMessage + "): called"); // Reset the message count for a new test. messageCount = 0; // Take note of the role to be played. this.role = role; // Create a new connection to pass the test messages on. connection = TestClient.CreateConnection(TestClient.brokerUrl, TestClient.virtualHost); channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge); // Extract and retain the test parameters. numMessages = assignRoleMessage.Headers.GetInt("P2P_NUM_MESSAGES"); string queueAndKeyName = assignRoleMessage.Headers.GetString("P2P_QUEUE_AND_KEY_NAME"); channel.DeclareQueue(queueAndKeyName, false, true, true); channel.Bind(queueAndKeyName, ExchangeNameDefaults.DIRECT, queueAndKeyName); sendDestination = queueAndKeyName; log.Debug("numMessages = " + numMessages); log.Debug("sendDestination = " + sendDestination); log.Debug("role = " + role); switch (role) { // Check if the sender role is being assigned, and set up a message producer if so. case Roles.SENDER: publisher = channel.CreatePublisherBuilder() .WithExchangeName(ExchangeNameDefaults.DIRECT) .WithRoutingKey(sendDestination) .Create(); break; // Otherwise the receiver role is being assigned, so set this up to listen for messages. case Roles.RECEIVER: IMessageConsumer consumer = channel.CreateConsumerBuilder(sendDestination).Create(); consumer.OnMessage += new MessageReceivedDelegate(OnMessage); break; } connection.Start(); }
/// <summary> Creates a topic listener using the specified broker URL. </summary> /// /// <param name="connectionUri">The broker URL to listen on.</param> TopicListener(string connectionUri) { LogDebug("TopicListener(string connectionUri = " + connectionUri + "): called"); // Create a connection to the broker. IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(connectionUri); connection = new AMQConnection(connectionInfo); // Establish a session on the broker. channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1); // Set up a queue to listen for test messages on. string topicQueueName = channel.GenerateUniqueName(); channel.DeclareQueue(topicQueueName, false, true, true); // Set this listener up to listen for incoming messages on the test topic queue. channel.Bind(topicQueueName, ExchangeNameDefaults.TOPIC, CONTROL_ROUTING_KEY); IMessageConsumer consumer = channel.CreateConsumerBuilder(topicQueueName) .Create(); consumer.OnMessage += new MessageReceivedDelegate(OnMessage); // Set up this listener with a producer to send the reports on. publisher = channel.CreatePublisherBuilder() .WithExchangeName(ExchangeNameDefaults.DIRECT) .WithRoutingKey(RESPONSE_ROUTING_KEY) .Create(); connection.Start(); Console.WriteLine("Waiting for messages..."); while (true) { if (shutdownReceivedEvt.WaitOne(TIMEOUT, true)) { Console.WriteLine("message was received"); } else { Console.WriteLine("timeout elapsed"); } } }
/// <summary> /// Creates the test connection with a fail-over set up, and a producer/consumer pair on that connection. /// </summary> /// [SetUp] public void Init(IConnectionInfo connectionInfo) { //log4net.Config.BasicConfigurator.Configure(); // Reset all counts. messagesSent = 0; messagesReceived = 0; failedOver = false; _extraMessage = 0; PromptAndWait("Ensure both brokers are running, then press Enter"); // Create a connection for the test. _connection = new AMQConnection(connectionInfo); _connection.ConnectionListener = this; // Create a consumer to receive the test messages. IChannel receivingChannel = _connection.CreateChannel(false, _acknowledgeMode); string queueName = receivingChannel.GenerateUniqueName(); receivingChannel.DeclareQueue(queueName, false, true, true); receivingChannel.Bind(queueName, "amq.direct", queueName); IMessageConsumer consumer = receivingChannel.CreateConsumerBuilder(queueName) .WithPrefetchLow(30) .WithPrefetchHigh(60).Create(); consumer.OnMessage = new MessageReceivedDelegate(OnMessage); _connection.Start(); // Create a publisher to send the test messages. publishingChannel = _connection.CreateChannel(transacted, AcknowledgeMode.NoAcknowledge); publisher = publishingChannel.CreatePublisherBuilder() .WithRoutingKey(queueName) .Create(); _log.Debug("connection = " + _connection); _log.Debug("connectionInfo = " + connectionInfo); _log.Debug("connection.AsUrl = " + _connection.toURL()); _log.Debug("AcknowledgeMode is " + _acknowledgeMode); }
/// <summary> /// Creates a topic publisher that will send the specifed number of messages and expect the specifed number of report back from test /// subscribers. /// </summary> /// /// <param name="connectionUri">The broker URL.</param> /// <param name="numMessages">The number of messages to send in each test.</param> /// <param name="numSubscribers">The number of subscribes that are expected to reply with a report.</param> TopicPublisher(string connectionUri, int numMessages, int numSubscribers) { log.Debug("TopicPublisher(string connectionUri = " + connectionUri + ", int numMessages = " + numMessages + ", int numSubscribers = " + numSubscribers + "): called"); // Create a connection to the broker. IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(connectionUri); connection = new AMQConnection(connectionInfo); // Establish a session on the broker. channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1); // Set up a queue to listen for reports on. string responseQueueName = channel.GenerateUniqueName(); channel.DeclareQueue(responseQueueName, false, true, true); // Set this listener up to listen for reports on the response queue. channel.Bind(responseQueueName, ExchangeNameDefaults.DIRECT, RESPONSE_ROUTING_KEY); //channel.Bind(responseQueueName, "<<default>>", RESPONSE_ROUTING_KEY); IMessageConsumer consumer = channel.CreateConsumerBuilder(responseQueueName) .Create(); consumer.OnMessage += new MessageReceivedDelegate(OnMessage); // Set up this listener with a producer to send the test messages and report requests on. publisher = channel.CreatePublisherBuilder() .WithExchangeName(ExchangeNameDefaults.TOPIC) .WithRoutingKey(CONTROL_ROUTING_KEY) .Create(); // Keep the test parameters. this.numMessages = numMessages; this.numSubscribers = numSubscribers; connection.Start(); Console.WriteLine("Sending messages and waiting for reports..."); }
/// <summary> /// Creates a topic publisher that will send the specifed number of messages and expect the specifed number of report back from test /// subscribers. /// </summary> /// /// <param name="connectionUri">The broker URL.</param> /// <param name="numMessages">The number of messages to send in each test.</param> /// <param name="numSubscribers">The number of subscribes that are expected to reply with a report.</param> TopicPublisher(string connectionUri, int numMessages, int numSubscribers) { log.Debug("TopicPublisher(string connectionUri = " + connectionUri + ", int numMessages = "+ numMessages + ", int numSubscribers = " + numSubscribers + "): called"); // Create a connection to the broker. IConnectionInfo connectionInfo = QpidConnectionInfo.FromUrl(connectionUri); connection = new AMQConnection(connectionInfo); // Establish a session on the broker. channel = connection.CreateChannel(false, AcknowledgeMode.AutoAcknowledge, 1); // Set up a queue to listen for reports on. string responseQueueName = channel.GenerateUniqueName(); channel.DeclareQueue(responseQueueName, false, true, true); // Set this listener up to listen for reports on the response queue. channel.Bind(responseQueueName, ExchangeNameDefaults.DIRECT, RESPONSE_ROUTING_KEY); //channel.Bind(responseQueueName, "<<default>>", RESPONSE_ROUTING_KEY); IMessageConsumer consumer = channel.CreateConsumerBuilder(responseQueueName) .Create(); consumer.OnMessage += new MessageReceivedDelegate(OnMessage); // Set up this listener with a producer to send the test messages and report requests on. publisher = channel.CreatePublisherBuilder() .WithExchangeName(ExchangeNameDefaults.TOPIC) .WithRoutingKey(CONTROL_ROUTING_KEY) .Create(); // Keep the test parameters. this.numMessages = numMessages; this.numSubscribers = numSubscribers; connection.Start(); Console.WriteLine("Sending messages and waiting for reports..."); }