本文整理汇总了C#中MessagingFactory.CreateMessageReceiver方法的典型用法代码示例。如果您正苦于以下问题:C# MessagingFactory.CreateMessageReceiver方法的具体用法?C# MessagingFactory.CreateMessageReceiver怎么用?C# MessagingFactory.CreateMessageReceiver使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessagingFactory
的用法示例。
在下文中一共展示了MessagingFactory.CreateMessageReceiver方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AzureMessageConsumer
protected static void AzureMessageConsumer(MessagingFactory f)
{
//use the already created messaging factory to create a msg receiver
MessageReceiver testQueueReceiver = f.CreateMessageReceiver("colors");
while (true)
{
using (BrokeredMessage retrievedMessage = testQueueReceiver.Receive())
{
try
{
string msgResult = retrievedMessage.GetBody<string>();
//call SP to insert the data into the proper table
InsertSQL(msgResult);
Console.WriteLine("Message received: " + msgResult);
retrievedMessage.Complete();
}
catch (Exception ex)
{
Console.WriteLine(ex.ToString());
retrievedMessage.Abandon();
}
}
}
}
示例2: MessageProcessor
public MessageProcessor(string queueName, string serviceNameSpace, string issuer, string key)
{
// Create Token Provider and Service Uri
var tokenProvider = TokenProvider.CreateSharedSecretTokenProvider(issuer, key);
var serviceUri = ServiceBusEnvironment.CreateServiceUri("sb", serviceNameSpace, string.Empty);
// Create a messaging receiver
_factory = MessagingFactory.Create(serviceUri, tokenProvider);
_messageReceiver = _factory.CreateMessageReceiver(queueName);
//_messageSender = _factory.CreateMessageSender(queueName);
}
示例3: RunDeviceEndpoint
static async Task RunDeviceEndpoint(IPEndPoint deviceEP, MessagingFactory messagingFactory)
{
var deviceServer = new TcpListener(deviceEP);
deviceServer.Start(10);
try
{
do
{
TcpClient connection = await deviceServer.AcceptTcpClientAsync();
if (connection != null)
{
try
{
var pendingSessions = new Queue<string>();
connection.NoDelay = true; // flush writes immediately to the wire
connection.ReceiveTimeout = timeout;
NetworkStream deviceConnectionStream = connection.GetStream();
var readBuffer = new byte[64];
if (await deviceConnectionStream.ReadAsync(readBuffer, 0, 4) == 4)
{
int deviceId = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(readBuffer, 0));
try
{
Task<BrokeredMessage> queueReceive = null;
Task<int> socketRead = null;
Task pingDelay = null;
var cancelPing = new CancellationTokenSource();
// set up the receiver for the per-device queue and senbder for the response queue
var deviceQueueReceiver = messagingFactory.CreateMessageReceiver(string.Format("dev-{0:X8}", deviceId), ReceiveMode.PeekLock);
var responseQueueSender = messagingFactory.CreateMessageSender(string.Format("ingress"));
do
{
// receive from the queue
queueReceive = queueReceive ?? deviceQueueReceiver.ReceiveAsync();
// read from the socket
socketRead = socketRead ?? deviceConnectionStream.ReadAsync(readBuffer, 0, 1);
// ping delay
pingDelay = pingDelay ?? Task.Delay(TimeSpan.FromSeconds(235), cancelPing.Token);
// wait for any of the four operations (including completion) to be done
var completedTask = await Task.WhenAny(queueReceive, socketRead, pingDelay, ClosingEvent.Task);
if (completedTask == socketRead)
{
try
{
// read from the socket completed and not a ping
if (socketRead.Result == 1)
{
if (readBuffer[0] != PingFrame[0])
{
await responseQueueSender.SendAsync(new BrokeredMessage()
{
SessionId = pendingSessions.Dequeue(),
Properties = {{"Ack", (int) readBuffer[0]}}
});
}
}
else
{
// no more data from the socket. Break out of the loop.
break;
}
}
finally
{
socketRead = null;
}
}
else if (completedTask == queueReceive)
{
try
{
// read from the queue completed
var message = queueReceive.Result;
if (message != null)
{
var command = message.Properties["Cmd"] as string;
if (command != null)
{
switch (command.ToUpperInvariant())
{
case "ON":
pendingSessions.Enqueue(message.ReplyToSessionId);
await deviceConnectionStream.WriteAsync(OnFrame, 0, OnFrame.Length);
await message.CompleteAsync();
cancelPing.Cancel();
break;
case "OFF":
pendingSessions.Enqueue(message.ReplyToSessionId);
await deviceConnectionStream.WriteAsync(OffFrame, 0, OffFrame.Length);
await message.CompleteAsync();
cancelPing.Cancel();
break;
}
}
//.........这里部分代码省略.........
示例4: CreateMessageReceiver
/// <summary>
/// Creates a <see cref="MessageReceiver"/> for the specified ServiceBus entity.
/// </summary>
/// <remarks>
/// You can override this method to customize the <see cref="MessageReceiver"/>.
/// </remarks>
/// <param name="factory">The <see cref="MessagingFactory"/> to use.</param>
/// <param name="entityPath">The ServiceBus entity to create a <see cref="MessageReceiver"/> for.</param>
/// <returns></returns>
public virtual MessageReceiver CreateMessageReceiver(MessagingFactory factory, string entityPath)
{
if (factory == null)
{
throw new ArgumentNullException("factory");
}
if (string.IsNullOrEmpty(entityPath))
{
throw new ArgumentNullException("entityPath");
}
MessageReceiver receiver = factory.CreateMessageReceiver(entityPath);
receiver.PrefetchCount = _config.PrefetchCount;
return receiver;
}