コード例 #1
0
        public async Task Subscribe(string endpointName, Action <IRoutableMessage> MessageHandler, Func <Exception, Task> ErrorHandler)
        {
            // Get the subscription information from the endpointName setting in the configuration file
            IApplicationSecretsConnectionStrings subscriber = _applicationSecrets.Secret(endpointName);
            string connectionString = subscriber.Value;

            string topicName        = subscriber[Topic];
            string subscriptionName = subscriber[Subscription];

            string path     = EntityNameHelper.FormatSubscriptionPath(topicName, subscriptionName);
            var    receiver = new MessageReceiver(connectionString, path);

            receiver.RegisterMessageHandler(
                async(message, cancellationToken) =>
            {
                await receiver.CompleteAsync(message.SystemProperties.LockToken);
                string body          = Encoding.UTF8.GetString(message.Body);
                IRoutableMessage msg = body.MessageFromBus();
                MessageHandler(msg);
            },
                new MessageHandlerOptions(e => ErrorHandler(e.Exception))
            {
                AutoComplete       = false,
                MaxConcurrentCalls = 2
            });
        }
コード例 #2
0
        static void MessageHandler(IRoutableMessage message)
        {
            message.TraceInformation("Received from service bus");
            RegisterClientRequest request = message.GetPayload <RegisterClientRequest>();

            request.TraceInformation("Payload");
        }
コード例 #3
0
        public async Task Publish(IRoutableMessage message)
        {
            try
            {
                // Get the connection string from the destination address in the message
                IApplicationSecretsConnectionStrings publisher = _applicationSecrets.Secret(message.Recipient);

                // Create a sender for the topic
                string  topicName         = publisher[Topic];
                string  connectionString  = publisher.Value;
                Message serviceBusMessage = new Message(Encoding.UTF8.GetBytes(message.ToString()));

                ISenderClient topicClient = new TopicClient(connectionString, topicName);
                await topicClient.SendAsync(serviceBusMessage);
            }
            catch (Exception e)
            {
                Console.WriteLine(e);
                throw;
            }
        }
コード例 #4
0
ファイル: RequestMessage.cs プロジェクト: HelloKitty/GladNet2
		public void ExportRoutingDataTo(IRoutableMessage message)
		{
			//So, this is sorta a hack but it's a good one
			//for preformance
			if (message is RequestMessage)
			{
				RequestMessage castedMessage = message as RequestMessage;
				lock (syncObj)
				{
					//No reason to copy null stack
					if (_routingCodeStack != null)
						//We should transfer the routing stack but also preserve the other routing stack
						//We probably won't need it but just in case the user wants to do something with it still
						castedMessage._routingCodeStack = new Stack<int>(_routingCodeStack.Reverse()); //We must create a reverse copy of the stack:http://stackoverflow.com/questions/7391348/c-sharp-clone-a-stack
				}
			}
			else
			{
				if (message is ResponseMessage)
				{
					ResponseMessage castedMessage = message as ResponseMessage;
					lock (syncObj)
					{
						//No reason to copy null stack
						if (_routingCodeStack != null)
							//We should transfer the routing stack but also preserve the other routing stack
							//We probably won't need it but just in case the user wants to do something with it still
							castedMessage._routingCodeStack = new Stack<int>(_routingCodeStack.Reverse()); //We must create a reverse copy of the stack:http://stackoverflow.com/questions/7391348/c-sharp-clone-a-stack
					}
				}
			}

		}
コード例 #5
0
 public async Task Publish(IRoutableMessage message)
 {
     message.TraceInformation("Local service bus publish not implemented yet");
 }
コード例 #6
0
        public static IRoutableMessage MessageFromBus(this string message)
        {
            IRoutableMessage msg = JsonConvert.DeserializeObject <RoutableMessage>(message);

            return(msg);
        }
コード例 #7
0
 public static async Task Publish(this object message, IMessageBus bus, string sender, string recipient)
 {
     IRoutableMessage msg = message.BusTopicMessage(sender, recipient);
     await bus.Publish(msg);
 }