コード例 #1
0
        public void StartRedisListener(SetEventOnRampMessageReceived setEventOnRampMessageReceived)
        {
            try
            {
                ConnectionMultiplexer redis =
                    ConnectionMultiplexer.Connect(ConfigurationBag.Configuration.RedisConnectionString);

                ISubscriber sub = redis.GetSubscriber();

                sub.Subscribe("*", (channel, message) =>
                {
                    byte[] byteArray = message;
                    BubblingObject bubblingObject = BubblingObject.DeserializeMessage(byteArray);
                    setEventOnRampMessageReceived(bubblingObject);
                });
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(
                    ConfigurationBag.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.LogLevelError,
                    Constant.TaskCategoriesEventHubs,
                    ex,
                    Constant.LogLevelError);
            }
        }
コード例 #2
0
        public void StartRedisListener(SetEventOnRampMessageReceived setEventOnRampMessageReceived)
        {
            try
            {
                ConnectionMultiplexer redis = ConnectionMultiplexer.Connect(Configuration.RedisConnectionString());

                ISubscriber sub = redis.GetSubscriber();

                sub.Subscribe("*", (channel, message) => {
                    byte[] byteArray = (byte[])message;
                    SkeletonMessage skeletonMessage = SkeletonMessage.DeserializeMessage(byteArray);
                    setEventOnRampMessageReceived(skeletonMessage);
                });
                Thread.Sleep(Timeout.Infinite);
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(
                    Configuration.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.DefconOne,
                    Constant.TaskCategoriesEventHubs,
                    ex,
                    EventLogEntryType.Error);
            }
        }
コード例 #3
0
        /// <summary>
        ///     Initialize the onramp engine.
        /// </summary>
        /// <param name="onRampPatternComponent">
        ///     The off ramp pattern component.
        /// </param>
        public void Init(string onRampPatternComponent)
        {
            // Delegate event for ingestor where ReceiveMessageOnRamp is the event
            receiveMessageOnRampDelegate = ReceiveMessageOnRamp;

            LogEngine.WriteLog(
                ConfigurationBag.EngineName,
                "Start On Ramp engine.",
                Constant.LogLevelError,
                Constant.TaskCategoriesError,
                null,
                Constant.LogLevelInformation);

            // Inizialize the MSPC

            // Load event up stream external component
            var eventsUpStreamComponent = Path.Combine(
                ConfigurationBag.Configuration.DirectoryOperativeRootExeName,
                ConfigurationBag.Configuration.EventsStreamComponent);

            // Create the reflection method cached
            var assembly = Assembly.LoadFrom(eventsUpStreamComponent);

            // Main class loggingCreateOnRamptream
            var assemblyClass = (from t in assembly.GetTypes()
                                 let attributes = t.GetCustomAttributes(typeof(EventsOnRampContract), true)
                                                  where t.IsClass && attributes != null && attributes.Length > 0
                                                  select t).First();


            OnRampStream = Activator.CreateInstance(assemblyClass) as IOnRampStream;
            OnRampStream.Run(receiveMessageOnRampDelegate);
        }
コード例 #4
0
ファイル: OnRampEngine.cs プロジェクト: debiaggi/GrabCaster
        /// <summary>
        /// Initialize the onramp engine.
        /// </summary>
        /// <param name="offRampPatternComponent">
        /// The off ramp pattern component.
        /// </param>
        public void Init(string offRampPatternComponent)
        {
            if (Configuration.RunLocalOnly())
            {
                LogEngine.WriteLog(Configuration.EngineName,
                                   $"This GrabCaster point is configured for local only execution.",
                                   Constant.DefconOne,
                                   Constant.TaskCategoriesError,
                                   null,
                                   EventLogEntryType.Warning);
                return;
            }
            // Delegate event for ingestor where ReceiveMessageOnRamp is the event
            this.receiveMessageOnRampDelegate = this.ReceiveMessageOnRamp;

            LogEngine.WriteLog(
                Configuration.EngineName,
                "Start On Ramp engine.",
                Constant.DefconOne,
                Constant.TaskCategoriesError,
                null,
                EventLogEntryType.Information);

            // Inizialize the MSPC

            // Load event up stream external component
            var eventsUpStreamComponent = Path.Combine(
                Configuration.DirectoryOperativeRootExeName(),
                Configuration.EventsStreamComponent());

            // Create the reflection method cached
            var assembly = Assembly.LoadFrom(eventsUpStreamComponent);

            // Main class logging
            var assemblyClass = (from t in assembly.GetTypes()
                                 let attributes = t.GetCustomAttributes(typeof(EventsDownStreamContract), true)
                                                  where t.IsClass && attributes != null && attributes.Length > 0
                                                  select t).First();

            var classAttributes = assemblyClass.GetCustomAttributes(typeof(EventsDownStreamContract), true);

            if (classAttributes.Length > 0)
            {
                Debug.WriteLine("EventsDownStreamContract - methodRun caller");
                methodRun = assemblyClass.GetMethod("Run");
            }

            classInstance = Activator.CreateInstance(assemblyClass, null);

            ParametersRet[0] = this.receiveMessageOnRampDelegate;
            methodRun.Invoke(classInstance, ParametersRet);
        }
コード例 #5
0
 public void Run(SetEventOnRampMessageReceived setEventOnRampMessageReceived)
 {
     try
     {
         var myNewThread = new Thread(() => StartRedisListener(setEventOnRampMessageReceived));
         myNewThread.Start();
     }
     catch (Exception ex)
     {
         LogEngine.WriteLog(
             ConfigurationBag.EngineName,
             $"Error in {MethodBase.GetCurrentMethod().Name}",
             Constant.LogLevelError,
             Constant.TaskCategoriesEventHubs,
             ex,
             Constant.LogLevelError);
     }
 }
コード例 #6
0
        public void Run(SetEventOnRampMessageReceived setEventOnRampMessageReceived)
        {
            try
            {
                // Assign the delegate
                SetEventOnRampMessageReceived = setEventOnRampMessageReceived;
                // Load vars
                var eventHubConnectionString = ConfigurationBag.Configuration.AzureNameSpaceConnectionString;
                var eventHubName             = ConfigurationBag.Configuration.GroupEventHubsName;

                LogEngine.WriteLog(
                    ConfigurationBag.EngineName,
                    $"Event Hubs transfort Type: {ConfigurationBag.Configuration.ServiceBusConnectivityMode}",
                    Constant.LogLevelError,
                    Constant.TaskCategoriesError,
                    null,
                    Constant.LogLevelInformation);

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

                //If not exit it create one, drop brachets because Azure rules
                var eventHubConsumerGroup =
                    string.Concat(ConfigurationBag.EngineName, "_", ConfigurationBag.Configuration.ChannelId)
                    .Replace("{", "")
                    .Replace("}", "")
                    .Replace("-", "");
                var nsManager = NamespaceManager.CreateFromConnectionString(builder.ToString());
                Debug.WriteLine($"Initializing Group Name {eventHubConsumerGroup}");

                Debug.WriteLine("Start DirectRegisterEventReceiving.");

                // 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();
                }

                Debug.WriteLine(
                    "After DirectRegisterEventReceiving Downstream running.");
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(
                    ConfigurationBag.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name} - Hint: Check if the firewall outbound port 5671 is opened.",
                    Constant.LogLevelError,
                    Constant.TaskCategoriesEventHubs,
                    ex,
                    Constant.LogLevelError);
            }
        }