Beispiel #1
0
 private static void ReceiveDirectFromPartition(
     EventHubClient eventHubClient,
     string partitionId,
     string consumerGroup)
 {
     try
     {
         var group = eventHubClient.GetConsumerGroup(consumerGroup);
         EventHubReceiver receiver = null;
         receiver = group.CreateReceiver(partitionId, DateTime.UtcNow);
         LogEngine.TraceInformation($"Direct Receiver created. Partition {partitionId}");
         while (true)
         {
             var message = receiver?.Receive();
             if (message != null)
             {
                 BubblingObject bubblingObject = BubblingObject.DeserializeMessage(message.GetBytes());
                 MessageIngestor.IngestMessagge(bubblingObject);
             }
         }
     }
     catch (Exception ex)
     {
         LogEngine.TraceError($"Error in {MethodBase.GetCurrentMethod().Name} - Error {ex.Message}");
     }
 }
Beispiel #2
0
        public void Run(MessageIngestor.SetEventActionEventEmbedded setEventActionEventEmbedded)
        {
            try
            {
                SetEventActionEventEmbedded = setEventActionEventEmbedded;

                //Load message ingestor
                MessageIngestor.Init(SetEventActionEventEmbedded);
                // Assign the delegate

                // Load vars
                var eventHubConnectionString = ConfigurationLibrary.AzureNameSpaceConnectionString();
                var eventHubName             = ConfigurationLibrary.GroupEventHubsName();

                LogEngine.TraceInformation(
                    $"Start GrabCaster DownStream - Point Id {ConfigurationLibrary.PointId()} - Point name {ConfigurationLibrary.PointName()} - Channel Id {ConfigurationLibrary.ChannelId()} - Channel name {ConfigurationLibrary.ChannelName()} ");

                var builder = new ServiceBusConnectionStringBuilder(eventHubConnectionString)
                {
                    TransportType =
                        TransportType.Amqp
                };

                //If not exit it create one, drop brachets because Azure rules
                var eventHubConsumerGroup = string.Concat(ConfigurationLibrary.EngineName(), "_",
                                                          ConfigurationLibrary.ChannelId().Replace("{", "").Replace("}", "").Replace("-", ""));

                var nsManager = NamespaceManager.CreateFromConnectionString(builder.ToString());

                LogEngine.TraceInformation(
                    $"Start DirectRegisterEventReceiving. - Initializing Group Name {eventHubConsumerGroup}");

                // Create Event Hubs
                var eventHubClient = EventHubClient.CreateFromConnectionString(builder.ToString(), eventHubName);
                // Create consumer
                nsManager.CreateConsumerGroupIfNotExists(eventHubName, eventHubConsumerGroup);

                var namespaceManager = NamespaceManager.CreateFromConnectionString(builder.ToString());
                var ehDescription    = namespaceManager.GetEventHub(eventHubName);
                // Use the default consumer group

                foreach (var partitionId in ehDescription.PartitionIds)
                {
                    var myNewThread =
                        new Thread(() => ReceiveDirectFromPartition(eventHubClient, partitionId, eventHubConsumerGroup));
                    myNewThread.Start();
                }

                LogEngine.TraceInformation("After DirectRegisterEventReceiving Downstream running.");
            }
            catch (Exception ex)
            {
                LogEngine.TraceError(
                    $"Error in {MethodBase.GetCurrentMethod().Name} - Hint: Check if the firewall outbound port 5671 is opened. - Error {ex.Message}");
            }
        }