本文整理汇总了C#中ISession.CreateDurableConsumer方法的典型用法代码示例。如果您正苦于以下问题:C# ISession.CreateDurableConsumer方法的具体用法?C# ISession.CreateDurableConsumer怎么用?C# ISession.CreateDurableConsumer使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ISession
的用法示例。
在下文中一共展示了ISession.CreateDurableConsumer方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ActiveMq
public ActiveMq(bool durable)
{
_connectionFactory = new ConnectionFactory("tcp://localhost:61616");
_connectionFactory.AsyncSend = true;
_connectionFactory.ProducerWindowSize = int.MaxValue;
_connection = _connectionFactory.CreateConnection();
_connection.ClientId = "13AC0CF8-65FE-4638-8B85-62210DD89BEE";
_connection.Start();
_session = _connection.CreateSession();
ActiveMQTopic topic = new ActiveMQTopic("topic");
_consumer = _session.CreateDurableConsumer(topic, "durable", "2 > 1", false);
_producer = _session.CreateProducer(topic);
_producer.DeliveryMode = durable ? MsgDeliveryMode.Persistent : MsgDeliveryMode.NonPersistent;
}
示例2: TryConnect
private void TryConnect()
{
Task.Factory.StartNew(() =>
{
while (!_cts.IsCancellationRequested)
{
if (!_isConnect)
{
_logger.Info("开始连接指令队列服务器![{0}-{1}]".GetFormat(_name, _uri));
try
{
_factory = new ConnectionFactory(_uri);
_connection = _factory.CreateConnection();
_connection.ConnectionInterruptedListener += () =>
{
_logger.Error("与指令队列服务器断开连接![{0}-{1}]".GetFormat(_name, _uri));
_isConnect = false;
};
_connection.ClientId = _clientId;
_connection.Start();
_session = _connection.CreateSession();
_consumer = _session.CreateDurableConsumer(new ActiveMQTopic(_name), _connection.ClientId, null, false);
_consumer.Listener += OnReceived;
_isConnect = true;
_logger.Info("连接指令队列服务器成功![{0}-{1}]".GetFormat(_name, _uri));
}
catch (Exception ex)
{
_logger.Error("连接指令队列服务器失败![{0}-{1}]".GetFormat(_name, _uri), ex);
_isConnect = false;
}
}
Thread.Sleep(10 * 1000);
}
}, _cts.Token);
}
示例3: CreateConsumer
/// <summary>
/// Creates a MessageConsumer for the given Session and Destination.
/// </summary>
/// <param name="session">The session to create a MessageConsumer for.</param>
/// <param name="destination">The destination to create a MessageConsumer for.</param>
/// <returns>The new MessageConsumer</returns>
protected IMessageConsumer CreateConsumer(ISession session, IDestination destination)
{
// Only pass in the NoLocal flag in case of a Topic:
// Some NMS providers, such as WebSphere MQ 6.0, throw IllegalStateException
// in case of the NoLocal flag being specified for a Queue.
if (PubSubDomain)
{
if (SubscriptionDurable && destination is ITopic)
{
return session.CreateDurableConsumer(
(ITopic) destination, DurableSubscriptionName, MessageSelector, PubSubNoLocal);
}
else
{
return session.CreateConsumer(destination, MessageSelector, PubSubNoLocal);
}
}
else
{
return session.CreateConsumer(destination, MessageSelector);
}
}
示例4: CreateConsumer
/// <summary>
/// Create a message consumer to the given destination
/// </summary>
/// <param name="session">session to connect to</param>
/// <param name="destination">destination topic to read from</param>
/// <param name="appendedText">optional text to append to durable subscriber name</param>
/// <returns>a consumer to the given destination</returns>
private IMessageConsumer CreateConsumer(ISession session, ITopic destination, string appendedText = null)
{
string subscriberId = ConfigurationManager.AppSettings["ActiveMQDurableSubscriberId"];
if (!string.IsNullOrEmpty(subscriberId))
return session.CreateDurableConsumer(destination, string.Concat(subscriberId, appendedText), null, false);
else
return session.CreateConsumer(destination);
}