Exemplo n.º 1
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);
            }
        }
Exemplo n.º 2
0
        public void PersistEventToStorage(byte[] messageBody, string messageId, string groupEventHubsStorageAccountName,
                                          string groupEventHubsStorageAccountKey)
        {
            try
            {
                var storageAccountName = groupEventHubsStorageAccountName;
                var storageAccountKey  = groupEventHubsStorageAccountKey;
                var connectionString   =
                    $"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey}";
                var storageAccount = CloudStorageAccount.Parse(connectionString);
                var blobClient     = storageAccount.CreateCloudBlobClient();

                // Retrieve a reference to a container.
                var container = blobClient.GetContainerReference(ConfigurationLibrary.GroupEventHubsName());

                // Create the container if it doesn't already exist.
                container.CreateIfNotExists();
                container.SetPermissions(
                    new BlobContainerPermissions {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });

                // Create the messageid reference
                var blockBlob = container.GetBlockBlobReference(messageId);
                blockBlob.UploadFromByteArray(messageBody, 0, messageBody.Length);
                LogEngine.TraceInformation("Event persisted -  Consistency Transaction Point created.");
            }
            catch (Exception ex)
            {
                LogEngine.TraceError($"Error in {MethodBase.GetCurrentMethod().Name} - Error {ex.Message}");
            }
        }
Exemplo n.º 3
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}");
            }
        }
Exemplo n.º 4
0
        public byte[] PersistEventFromStorage(string messageId, string groupEventHubsStorageAccountName,
                                              string groupEventHubsStorageAccountKey)
        {
            try
            {
                var storageAccountName = groupEventHubsStorageAccountName;
                var storageAccountKey  = groupEventHubsStorageAccountKey;
                var connectionString   =
                    $"DefaultEndpointsProtocol=https;AccountName={storageAccountName};AccountKey={storageAccountKey}";
                var storageAccount = CloudStorageAccount.Parse(connectionString);
                var blobClient     = storageAccount.CreateCloudBlobClient();

                // Retrieve a reference to a container.
                var container = blobClient.GetContainerReference(ConfigurationLibrary.GroupEventHubsName());

                // Create the container if it doesn't already exist.
                container.CreateIfNotExists();
                container.SetPermissions(
                    new BlobContainerPermissions {
                    PublicAccess = BlobContainerPublicAccessType.Blob
                });

                // Create the messageid reference
                var blockBlob = container.GetBlockBlobReference(messageId);

                blockBlob.FetchAttributes();
                var msgByteLength = blockBlob.Properties.Length;
                var msgContent    = new byte[msgByteLength];
                for (var i = 0; i < msgByteLength; i++)
                {
                    msgContent[i] = 0x20;
                }

                blockBlob.DownloadToByteArray(msgContent, 0);

                LogEngine.TraceInformation("Event persisted recovered -  Consistency Transaction Point restored.");

                return(msgContent);
            }
            catch (Exception ex)
            {
                LogEngine.TraceError($"Error in {MethodBase.GetCurrentMethod().Name} - Error {ex.Message}");
                return(null);
            }
        }