public EventHubClient CreatEventHubClientIfExist(string hubConnectString)
        {
            var hubClient = EventHubClient.CreateFromConnectionString(hubConnectString);

            hubClient.RetryPolicy = _retryPolicy;
            return(hubClient);
        }
        public async Task <Dictionary <string, MyEventHubPartitionInfo> > GetCurrentSequencesAsync(string hubsConnectionstring,
                                                                                                   string hubPath)
        {
            EventHubClient eventHubClient = CreatEventHubClientIfExist(hubsConnectionstring, hubPath);

            return(await GetCurrentSequencesAsync(eventHubClient));
        }
Exemple #3
0
        static void Main(string[] args)
        {
            SensorDevice = Microsoft.Azure.EventHubs.EventHubClient.CreateFromConnectionString(DeviceConnectionString);

            SetTimer();

            Console.WriteLine("\nPress the Enter key to exit the application...\n");
            Console.WriteLine("The application started at {0:HH:mm:ss.fff}", DateTime.Now);
            Console.ReadLine();
            SensorTimer.Stop();
            SensorTimer.Dispose();
        }
        public EventHubClient CreateEventHubClientFromIotHub(string eventHubCompatibleEndPoint, string compatibleName)
        {
            var connectionStringBuilder = new EventHubsConnectionStringBuilder(eventHubCompatibleEndPoint)
            {
                EntityPath       = compatibleName,
                OperationTimeout = TimeSpan.FromSeconds(180)
            };
            var hubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());

            hubClient.RetryPolicy = _retryPolicy;
            return(hubClient);
        }
        //public EventHubClient CreatEventHubClientWhetherHubExist(string servicebusConnectionstring, string hubPath)
        //{
        //    var namespaceManager = NamespaceManager.CreateFromConnectionString(servicebusConnectionstring);
        //    namespaceManager.Settings.OperationTimeout = TimeSpan.FromMinutes(10);
        //    namespaceManager.Settings.RetryPolicy = new Microsoft.ServiceBus.RetryExponential(TimeSpan.FromSeconds(3), TimeSpan.FromSeconds(10), 10);

        //    bool suc = false;
        //    int tryTimes = 100;
        //    EventHubClient client = null;
        //    while (!suc && (--tryTimes > 0))
        //    {
        //        try
        //        {
        //            EventHubDescription description;
        //            if (!namespaceManager.EventHubExists(hubPath))
        //            {
        //                description = new EventHubDescription(hubPath)
        //                {
        //                    MessageRetentionInDays = 7,
        //                    PartitionCount = 32
        //                };
        //                if (!namespaceManager.EventHubExists(hubPath))
        //                {
        //                    namespaceManager.CreateEventHub(description);
        //                }
        //            }

        //            var connectionStringBuilder = new EventHubsConnectionStringBuilder(servicebusConnectionstring)
        //            {
        //                EntityPath = hubPath,
        //                OperationTimeout = TimeSpan.FromSeconds(180)
        //            };
        //            client = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());


        //            client.RetryPolicy = _retryPolicy;
        //            suc = true;
        //        }
        //        catch (Exception)
        //        {
        //            Task.Delay(TimeSpan.FromSeconds(1)).GetAwaiter().GetResult();
        //        }
        //    }

        //    return client;
        //}


        public EventHubClient CreatEventHubClientIfExist(string hubsConnectionstring, string hubPath)
        {
            var connectionStringBuilder = new EventHubsConnectionStringBuilder(hubsConnectionstring)
            {
                EntityPath       = hubPath,
                OperationTimeout = TimeSpan.FromSeconds(180)
            };
            var hubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());

            hubClient.RetryPolicy = _retryPolicy;
            return(hubClient);
        }
Exemple #6
0
        private void Form1_Load(object sender, EventArgs e)
        {
            var connectionStringBuilder = new EH.EventHubsConnectionStringBuilder(EhConnectionString)
            {
                EntityPath = EhEntityPath
            };

            eventHubClient = EH.EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());
            string x = eventHubClient.EventHubName;

            var ri = eventHubClient.GetRuntimeInformationAsync().Result;

            //await SendMessagesToEventHub(100);
        }
Exemple #7
0
        public static async Task PushMessageToEventHubsAsync(AttachmentMetaData msg, string eventHubConnectionString)
        {
            // Creates an EventHubsConnectionStringBuilder object from the connection string, and sets the EntityPath.
            // Typically, the connection string should have the entity path in it, but for the sake of this simple scenario
            // we are using the connection string from the namespace.
            var connectionStringBuilder = new EventHubsConnectionStringBuilder(eventHubConnectionString)
            {
                EntityPath = Constants.EVENT_HUB_NAME
            };

            eventHubClient = Microsoft.Azure.EventHubs.EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());

            await  SendMessagesToEventHub(msg);

            await eventHubClient.CloseAsync();
        }
Exemple #8
0
 public EventHubClient(Microsoft.Azure.EventHubs.EventHubClient client)
 {
     _client = client;
 }
 public EventHubManager(string cs, string entityPath)
 {
     client  = EventHubClient.CreateFromConnectionString($"{cs};EntityPath={entityPath}");
     this.cs = cs;
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="EventHubPublisher"/> using the specified <see cref="EventHubs.EventHubClient"/> (consider setting the underlying
 /// <see cref="EventHubs.ClientEntity.RetryPolicy"/>) to allow for transient errors).
 /// </summary>
 /// <param name="client">The <see cref="EventHubs.EventHubClient"/>.</param>
 public EventHubPublisher(EventHubs.EventHubClient client) => _client = Check.NotNull(client, nameof(client));
Exemple #11
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EventHubPublisher"/> using the specified <see cref="EventHubs.EventHubClient"/> (consider setting the underlying
 /// <see cref="EventHubs.ClientEntity.RetryPolicy"/>) to allow for transient errors).
 /// </summary>
 /// <param name="client">The <see cref="EventHubs.EventHubClient"/>.</param>
 /// <param name="invoker">Enables the <see cref="Invoker"/> to be overridden; defaults to <see cref="EventHubPublisherInvoker"/>.</param>
 public EventHubPublisher(EventHubs.EventHubClient client, EventHubPublisherInvoker?invoker = null)
 {
     _client  = Check.NotNull(client, nameof(client));
     _invoker = invoker ?? new EventHubPublisherInvoker();
 }
 public IEventHubClient Create(Microsoft.Azure.EventHubs.EventHubClient client)
 {
     return(new EventHubClient(client, _serializer));
 }
 public EventHubClient(Microsoft.Azure.EventHubs.EventHubClient client, IEventHubSerializer serializer)
 {
     _client     = client;
     _serializer = serializer;
 }
Exemple #14
0
 protected EventDataSender(EventHubClient eventHubClient, string partitionId)
     : base(nameof(EventDataSender) + StringUtility.GetRandomString())
 {
     this.EventHubClient = eventHubClient;
     this.PartitionId    = partitionId;
 }
        public async Task <Dictionary <string, MyEventHubPartitionInfo> > GetCurrentSequencesAsync(EventHubClient eventHubClient)
        {
            Dictionary <string, MyEventHubPartitionInfo> dictionary = new Dictionary <string, MyEventHubPartitionInfo>();

            var eventHubRuntimeInfo = await eventHubClient.GetRuntimeInformationAsync();

            string[] partitionIds = eventHubRuntimeInfo.PartitionIds;

            foreach (var c in partitionIds)
            {
                var information = await eventHubClient.GetPartitionRuntimeInformationAsync(c);

                dictionary[c] = new MyEventHubPartitionInfo()
                {
                    PartitionId = c,
                    LastEnqueuedSequenceNumber = information.LastEnqueuedSequenceNumber,
                    LastEnqueuedTimeUtc        = information.LastEnqueuedTimeUtc
                };
            }

            return(dictionary);
        }