本文整理汇总了C#中IConnection.CreateChannel方法的典型用法代码示例。如果您正苦于以下问题:C# IConnection.CreateChannel方法的具体用法?C# IConnection.CreateChannel怎么用?C# IConnection.CreateChannel使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类IConnection
的用法示例。
在下文中一共展示了IConnection.CreateChannel方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Init
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;
}
示例2: TopicListener
/// <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");
}
}
}
示例3: TopicPublisher
/// <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...");
}
示例4: Init
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();
}
示例5: AssignRole
/// <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();
}
示例6: CreateChannel
/// <summary>Creates a channel.</summary>
/// <param name="connection">The connection.</param>
/// <returns>The channel.</returns>
public IModel CreateChannel(IConnection connection) { return connection.CreateChannel(this.IsSynchedLocalTransactionAllowed); }