Esempio n. 1
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}");
            }
        }
Esempio n. 2
0
        public bool CreateEventUpStream()
        {
            try
            {
                //EH Configuration
                connectionString = ConfigurationLibrary.AzureNameSpaceConnectionString();
                eventHubName     = ConfigurationLibrary.GroupEventHubsName();

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

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

                eventHubClient = EventHubClient.CreateFromConnectionString(builder.ToString(), eventHubName);

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }