Ejemplo n.º 1
0
        private static void SendTestMessageToTopic(Uri uri, string topicName, bool serviceSupportsPartitions, bool requireSessions = false)
        {
            //the name of your application and the name of the Service, the default partition resolver and the topic name
            //to create a communication client factory:
            var resolver = ServicePartitionResolver.GetDefault();
            var factory  = new ServiceBusTopicCommunicationClientFactory(resolver, null);

            ServicePartitionClient <ServiceBusTopicCommunicationClient> servicePartitionClient;

            if (serviceSupportsPartitions)
            {
                //determine the partition and create a communication proxy
                var partitionKey = new ServicePartitionKey(0L);
                servicePartitionClient = new ServicePartitionClient <ServiceBusTopicCommunicationClient>(factory, uri, partitionKey);
            }
            else
            {
                servicePartitionClient = new ServicePartitionClient <ServiceBusTopicCommunicationClient>(factory, uri);
            }

            //use the proxy to send a message to the Service
            servicePartitionClient.InvokeWithRetry(c => c.SendMessage(CreateMessage(requireSessions)));

            Console.WriteLine($"Message sent to topic '{topicName}'");
        }
Ejemplo n.º 2
0
		private static void SendTestMessageToTopic(Uri uri, string topicName, bool serviceSupportsPartitions)
		{
			//the name of your application and the name of the Service, the default partition resolver and the topic name
			//to create a communication client factory:
			var factory = new ServiceBusTopicCommunicationClientFactory(ServicePartitionResolver.GetDefault(), topicName);
			
			ServicePartitionClient<ServiceBusTopicCommunicationClient> servicePartitionClient;

			if (serviceSupportsPartitions)
			{
				//determine the partition and create a communication proxy
				long partitionKey = 0L;
				servicePartitionClient = new ServicePartitionClient<ServiceBusTopicCommunicationClient>(factory, uri, partitionKey);
			}
			else
			{
				servicePartitionClient = new ServicePartitionClient<ServiceBusTopicCommunicationClient>(factory, uri);
			}
			
			//use the proxy to send a message to the Service
			servicePartitionClient.InvokeWithRetry(c => c.SendMessage(CreateMessage()));

			Console.WriteLine("Message sent to topic");
		}