本文整理汇总了C#中MessagingFactory.CreateMessageSender方法的典型用法代码示例。如果您正苦于以下问题:C# MessagingFactory.CreateMessageSender方法的具体用法?C# MessagingFactory.CreateMessageSender怎么用?C# MessagingFactory.CreateMessageSender使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类MessagingFactory
的用法示例。
在下文中一共展示了MessagingFactory.CreateMessageSender方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Bus
public Bus() {
connectionString = CloudConfigurationManager.GetSetting("Microsoft.ServiceBus.ConnectionString");
namespaceManager = NamespaceManager.CreateFromConnectionString(connectionString);
// Configure Topic Settings
var td = new TopicDescription(topicName);
td.MaxSizeInMegabytes = 5120;
td.DefaultMessageTimeToLive = new TimeSpan(0, 1, 0);
if (!namespaceManager.TopicExists(topicName)) {
namespaceManager.CreateTopic(topicName);
}
factory = MessagingFactory.CreateFromConnectionString(connectionString);
sender = factory.CreateMessageSender(topicName);
}
示例2: AzureMessageSender
protected static void AzureMessageSender(MessagingFactory f)
{
//use the already created messaging factory to create a msg sender
MessageSender testQueueSender = f.CreateMessageSender(databaseName);
SqlConnection conn = new SqlConnection(databaseConnection);
try
{
conn.Open();
SqlCommand cmd = new SqlCommand(execSendQuery, conn);
cmd.CommandType = System.Data.CommandType.StoredProcedure;
//parameters
cmd.Parameters.Add("@r", SqlDbType.NVarChar, 50).Direction = ParameterDirection.Output;
cmd.ExecuteNonQuery();
//read output
string result = Convert.ToString(cmd.Parameters["@r"].Value);
//craft and send message
BrokeredMessage message = new BrokeredMessage(result);
testQueueSender.Send(message);
Console.WriteLine("Message is sent: " + result);
cmd.Dispose();
}
catch (Exception o)
{
Console.WriteLine(o);
}
finally
{
if (conn != null)
{ conn.Close(); }
}
}
示例3: Initialize
/// <summary>
/// Initialize
/// </summary>
public void Initialize(string azureServerConnectionString)
{
//AzureMessageClient = PinkoConfiguration.QueueConfiguration[QueueName].Item2
// ? (MessageClientEntity)QueueClient.CreateFromConnectionString(azureServerConnectionString, QueueName)
// : (MessageClientEntity)TopicClient.CreateFromConnectionString(azureServerConnectionString, QueueName);
//IsTopic = AzureMessageClient is TopicClient;
// Internal memory message bus
_messageHandlerManager = PinkoContainer.Resolve<MessageHandlerManager>().Initialize();
// Azure msg factory
var tokenProvider = TokenProvider.CreateSharedSecretTokenProvider("pinko-app-bus", "S6c6FYYpdWvOLscjmUyJWQDiQd01gxENzm+W/FSjOk4=");
_messageFactory = MessagingFactory.Create(AzureNamespaceManager.Address, tokenProvider);
_msgSender = _messageFactory.CreateMessageSender(QueueName);
// http://msdn.microsoft.com/en-us/library/windowsazure/hh699844.aspx
// http://msdn.microsoft.com/en-us/library/windowsazure/microsoft.servicebus.messaging.messagingfactory.aspx
//_azureNamespaceManager.CreateSubscription(queueName,"PinkoTopic");
//_azureNamespaceManager.crea
//MessageReceiver receiver = .CreateMessageReceiver("DataCollectionTopic/subscriptions/Inventory");
//BrokeredMessage receivedMessage = receiver.Receive();
//try
//{
// ProcessMessage(receivedMessage);
// receivedMessage.Complete();
//}
//catch (Exception e)
//{
// receivedMessage.Abandon();
//}
//Similar to using queues, the simplest way to receive messages from a subscription is to use a MessageReceiver object which you can create directly from the MessagingFactory using CreateMessageReceiver. You can use one of the two different receive modes (ReceiveAndDelete and PeekLock), as discussed in Creating Applications that Use Service Bus Queues.
//Note that when you create a MessageReceiver for subscriptions, the entityPath parameter is of the form topicPath/subscriptions/subscriptionName. Therefore, to create a MessageReceiver for the Inventory subscription of the DataCollectionTopic topic, entityPath must be DataCollectionTopic/subscriptions/Inventory. The code appears as follows:
}
示例4: 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;
}
}
//.........这里部分代码省略.........