Ejemplo n.º 1
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);
            }
        }
Ejemplo n.º 2
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)
             {
                 SkeletonMessage skeletonMessage = SkeletonMessage.DeserializeMessage(message.GetBytes());
                 MessageIngestor.IngestMessagge(skeletonMessage);
             }
         }
     }
     catch (Exception ex)
     {
         LogEngine.TraceError($"Error in {MethodBase.GetCurrentMethod().Name} - Error {ex.Message}");
     }
 }
Ejemplo n.º 3
0
 /// <summary>
 ///     Send a EventMessage message
 ///     invio importantissimo perche spedisce eventi e oggetti in array bytela dimensione e strategica
 /// </summary>
 /// <param name="message"></param>
 public void SendMessage(SkeletonMessage message)
 {
     try
     {
         byte[]    byteArrayBytes = SkeletonMessage.SerializeMessage(message);
         EventData evtData        = new EventData(byteArrayBytes);
         eventHubClient.Send(evtData);
     }
     catch (Exception ex)
     {
         LogEngine.TraceError($"Error in {MethodBase.GetCurrentMethod().Name} - Error {ex.Message}");
     }
 }
Ejemplo n.º 4
0
 /// <summary>
 ///     Send a EventMessage message
 ///     invio importantissimo perche spedisce eventi e oggetti in array bytela dimensione e strategica
 /// </summary>
 /// <param name="message"></param>
 public void SendMessage(SkeletonMessage message)
 {
     try
     {
         byte[]    byteArrayBytes = SkeletonMessage.SerializeMessage(message);
         EventData evtData        = new EventData(byteArrayBytes);
         eventHubClient.Send(evtData);
     }
     catch (Exception ex)
     {
         LogEngine.WriteLog(
             Configuration.EngineName,
             $"Error in {MethodBase.GetCurrentMethod().Name}",
             Constant.DefconOne,
             Constant.TaskCategoriesEventHubs,
             ex,
             EventLogEntryType.Error);
     }
 }
Ejemplo n.º 5
0
        /// <summary>
        /// Send a message service as Sync received or sync available in json format
        ///     e un messaggio di servizio, tipo, sync disponibile eccetera, non e importantissimo
        /// </summary>
        /// <param name="ehMessageType">
        /// The EH Message Type.
        /// </param>
        /// <param name="channelId">
        /// The Channel ID.
        /// </param>
        /// <param name="pointId">
        /// The Point ID.
        /// </param>
        /// <param name="idComponent">
        /// The ID Component.
        /// </param>
        /// <param name="subscriberId">
        /// The subscriber ID.
        /// </param>
        public static void SendNullMessageOnRamp(
            Configuration.MessageDataProperty ehMessageType,
            string channelId,
            string pointId,
            string idComponent,
            string subscriberId,
            string pointIdOverrided)
        {
            try
            {
                if (Configuration.RunLocalOnly())
                {
                    LogEngine.WriteLog(Configuration.EngineName,
                                       $"Impossible to send the message using a remote message storage provider, this GrabCaster point is configured for local only execution.",
                                       Constant.DefconOne,
                                       Constant.TaskCategoriesError,
                                       null,
                                       EventLogEntryType.Warning);
                    return;
                }

                // Meter and measuring purpose
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                var data = new SkeletonMessage(Encoding.UTF8.GetBytes(string.Empty));
                data.Properties.Add(Configuration.MessageDataProperty.Persisting.ToString(), false);

                // Set main security subscription
                data.Properties.Add(Configuration.GrabCasterMessageTypeName, Configuration.GrabCasterMessageTypeValue);

                data.Properties.Add(Configuration.MessageDataProperty.MessageId.ToString(), Guid.NewGuid().ToString());
                data.Properties.Add(
                    Configuration.MessageDataProperty.Message.ToString(),
                    Configuration.MessageDataProperty.Message.ToString());
                data.Properties.Add(Configuration.MessageDataProperty.SubscriberId.ToString(), subscriberId);
                data.Properties.Add(Configuration.MessageDataProperty.MessageType.ToString(), ehMessageType.ToString());

                string senderid = pointIdOverrided != null ? pointIdOverrided : Configuration.PointId();
                data.Properties.Add(Configuration.MessageDataProperty.SenderId.ToString(), senderid);
                data.Properties.Add(Configuration.MessageDataProperty.SenderName.ToString(), Configuration.PointName());
                data.Properties.Add(
                    Configuration.MessageDataProperty.SenderDescriprion.ToString(),
                    Configuration.PointDescription());
                data.Properties.Add(Configuration.MessageDataProperty.ChannelId.ToString(), Configuration.ChannelId());
                data.Properties.Add(
                    Configuration.MessageDataProperty.ChannelName.ToString(),
                    Configuration.ChannelName());
                data.Properties.Add(
                    Configuration.MessageDataProperty.ChannelDescription.ToString(),
                    Configuration.ChannelDescription());
                data.Properties.Add(Configuration.MessageDataProperty.ReceiverChannelId.ToString(), channelId);
                data.Properties.Add(Configuration.MessageDataProperty.ReceiverPointId.ToString(), pointId);
                data.Properties.Add(Configuration.MessageDataProperty.IdComponent.ToString(), idComponent);

                stopWatch.Stop();
                var ts = stopWatch.Elapsed;
                data.Properties.Add(Configuration.MessageDataProperty.OperationTime.ToString(), ts.Milliseconds);

                // Queue the data
                lock (offRampEngine)
                {
                    offRampEngine.Enqueue(data);
                }

                LogEngine.ConsoleWriteLine(
                    $"Sent Message Type: {ehMessageType} - To ChannelID: {channelId} PointID: {pointId}",
                    ConsoleColor.DarkMagenta);
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(
                    Configuration.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.DefconOne,
                    Constant.TaskCategoriesEventHubs,
                    ex,
                    EventLogEntryType.Error);
            }
        }
Ejemplo n.º 6
0
        /// <summary>
        /// TODO The send message on ramp.
        /// </summary>
        /// <param name="bubblingTriggerConfiguration">
        /// TODO The bubbling trigger configuration.
        /// </param>
        /// <param name="ehMessageType">
        /// TODO The eh message type.
        /// </param>
        /// <param name="channelId">
        /// TODO The channel id.
        /// </param>
        /// <param name="pointId">
        /// TODO The point id.
        /// </param>
        /// <param name="properties">
        /// TODO The properties.
        /// </param>
        public static void SendMessageOnRamp(
            object bubblingTriggerConfiguration,
            Configuration.MessageDataProperty ehMessageType,
            string channelId,
            string pointId,
            Dictionary <string, object> properties,
            string pointIdOverrided)
        {
            try
            {
                if (Configuration.RunLocalOnly())
                {
                    LogEngine.WriteLog(Configuration.EngineName,
                                       $"Impossible to send the message using a remote message storage provider, this GrabCaster point is configured for local only execution.",
                                       Constant.DefconOne,
                                       Constant.TaskCategoriesError,
                                       null,
                                       EventLogEntryType.Warning);
                    return;
                }

                // Meter and measuring purpose
                var stopWatch = new Stopwatch();
                stopWatch.Start();
                byte[] serializedMessage = null;
                // Create EH data message
                if (ehMessageType != Configuration.MessageDataProperty.ByteArray)
                {
                    serializedMessage = SerializationEngine.ObjectToByteArray(bubblingTriggerConfiguration);
                }
                else
                {
                    serializedMessage = (byte[])bubblingTriggerConfiguration;
                }

                var             messageId = Guid.NewGuid().ToString();
                SkeletonMessage data      = new SkeletonMessage(null);

                // IF > 256kb then persist
                if (serializedMessage.Length > secondaryPersistProviderByteSize && !secondaryPersistProviderEnabled)
                {
                    LogEngine.WriteLog(Configuration.EngineName,
                                       $"Error in {MethodBase.GetCurrentMethod().Name} - Impossible to send the message, the message body size if bigger than the secondaryPersistProviderByteSize paramenter but the secondaryPersistProviderEnabled is false.\rConsider to enable the secondaryPersistProviderEnabled paramanter in the config file and configure the storage component.",
                                       Constant.DefconOne,
                                       Constant.TaskCategoriesError,
                                       null,
                                       EventLogEntryType.Error);

                    return;
                }

                if (serializedMessage.Length > secondaryPersistProviderByteSize && secondaryPersistProviderEnabled)
                {
                    data.Body = Encoding.UTF8.GetBytes(messageId);
                    ParametersCreateEventUpStream[0] = serializedMessage;
                    ParametersCreateEventUpStream[1] = messageId;
                    methodPersistEventToBlob.Invoke(classInstanceDpp, ParametersCreateEventUpStream);
                    data.Properties.Add(Configuration.MessageDataProperty.Persisting.ToString(), true);
                }
                else
                {
                    data.Body = serializedMessage;
                    data.Properties.Add(Configuration.MessageDataProperty.Persisting.ToString(), false);
                }
                // Load custome Properties
                if (properties != null)
                {
                    foreach (var prop in properties)
                    {
                        data.Properties.Add(prop.Key, prop.Value);
                    }
                }

                data.Properties.Add(Configuration.MessageDataProperty.MessageId.ToString(), messageId);

                // Set main security subscription
                data.Properties.Add(Configuration.GrabCasterMessageTypeName, Configuration.GrabCasterMessageTypeValue);

                // Message context
                data.Properties.Add(
                    Configuration.MessageDataProperty.Message.ToString(),
                    Configuration.MessageDataProperty.Message.ToString());
                data.Properties.Add(Configuration.MessageDataProperty.MessageType.ToString(), ehMessageType.ToString());

                string senderid = pointIdOverrided != null? pointIdOverrided : Configuration.PointId();
                data.Properties.Add(Configuration.MessageDataProperty.SenderId.ToString(), senderid);

                data.Properties.Add(Configuration.MessageDataProperty.SenderName.ToString(), Configuration.PointName());
                data.Properties.Add(
                    Configuration.MessageDataProperty.SenderDescriprion.ToString(),
                    Configuration.PointDescription());
                data.Properties.Add(Configuration.MessageDataProperty.ChannelId.ToString(), Configuration.ChannelId());
                data.Properties.Add(
                    Configuration.MessageDataProperty.ChannelName.ToString(),
                    Configuration.ChannelName());
                data.Properties.Add(
                    Configuration.MessageDataProperty.ChannelDescription.ToString(),
                    Configuration.ChannelDescription());

                data.Properties.Add(Configuration.MessageDataProperty.ReceiverChannelId.ToString(), channelId);
                data.Properties.Add(Configuration.MessageDataProperty.ReceiverPointId.ToString(), pointId);

                stopWatch.Stop();
                var ts = stopWatch.Elapsed;
                data.Properties.Add(Configuration.MessageDataProperty.OperationTime.ToString(), ts.Milliseconds);

                lock (offRampEngine)
                {
                    if (ehMessageType == Configuration.MessageDataProperty.Event ||
                        ehMessageType == Configuration.MessageDataProperty.Trigger)
                    {
                        var bubblingEvent = (BubblingEvent)bubblingTriggerConfiguration;
                        if (Configuration.LoggingVerbose())
                        {
                            var serializedEvents = JsonConvert.SerializeObject(
                                bubblingEvent.Events,
                                Formatting.Indented,
                                new JsonSerializerSettings {
                                ReferenceLoopHandling = ReferenceLoopHandling.Ignore
                            });
                            LogEngine.ConsoleWriteLine(
                                $"Sent Message Type {ehMessageType}sent - Endpoints: {serializedEvents}",
                                ConsoleColor.Green);
                        }
                        else
                        {
                            LogEngine.ConsoleWriteLine($"Sent Message Type {ehMessageType}", ConsoleColor.Green);
                        }
                    }
                    else
                    {
                        LogEngine.ConsoleWriteLine($"Sent Message Type {ehMessageType}", ConsoleColor.Green);
                    }
                }
                offRampEngine.Enqueue(data);
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(
                    Configuration.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.DefconOne,
                    Constant.TaskCategoriesEventHubs,
                    ex,
                    EventLogEntryType.Error);
            }
        }
Ejemplo n.º 7
0
 public void SendMessage(SkeletonMessage message)
 {
     byte[] byteArrayBytes = SkeletonMessage.SerializeMessage(message);
     this.subscriber.Publish("*", byteArrayBytes);
 }
Ejemplo n.º 8
0
        private static void ReceiveDirectFromPartition(
            EventHubClient eventHubClient,
            string partitionId,
            string consumerGroup)
        {
            try
            {
                var group = eventHubClient.GetConsumerGroup(consumerGroup);

                var eventHubsStartingDateTimeReceiving =
                    DateTime.Parse(
                        Configuration.EventHubsStartingDateTimeReceiving() == "0"
                        // ReSharper disable once SpecifyACultureInStringConversionExplicitly
                            ? DateTime.UtcNow.ToString()
                            : Configuration.EventHubsStartingDateTimeReceiving());
                var eventHubsEpoch = Configuration.EventHubsEpoch();

                EventHubReceiver receiver = null;

                switch (Configuration.EventHubsCheckPointPattern())
                {
                case EventHubsCheckPointPattern.CheckPoint:
                    //Receiving from the last valid receiving point
                    receiver = group.CreateReceiver(partitionId, DateTime.UtcNow);
                    break;

                case EventHubsCheckPointPattern.Dt:

                    receiver = group.CreateReceiver(partitionId, eventHubsStartingDateTimeReceiving);
                    break;

                case EventHubsCheckPointPattern.Dtepoch:
                    receiver = group.CreateReceiver(partitionId, eventHubsStartingDateTimeReceiving, eventHubsEpoch);
                    break;

                case EventHubsCheckPointPattern.Dtutcnow:
                    receiver = group.CreateReceiver(partitionId, DateTime.UtcNow);
                    break;

                case EventHubsCheckPointPattern.Dtnow:
                    receiver = group.CreateReceiver(partitionId, DateTime.Now);
                    break;

                case EventHubsCheckPointPattern.Dtutcnowepoch:
                    receiver = group.CreateReceiver(partitionId, DateTime.UtcNow, eventHubsEpoch);
                    break;

                case EventHubsCheckPointPattern.Dtnowepoch:
                    receiver = group.CreateReceiver(partitionId, DateTime.Now, eventHubsEpoch);
                    break;
                }
                LogEngine.ConsoleWriteLine(
                    $"Direct Receiver created. Partition {partitionId}",
                    ConsoleColor.Yellow);
                while (true)
                {
                    var message = receiver?.Receive();
                    if (message != null)
                    {
                        SkeletonMessage skeletonMessage = SkeletonMessage.DeserializeMessage(message.GetBytes());
                        SetEventOnRampMessageReceived(skeletonMessage);
                    }
                }
            }
            catch (Exception ex)
            {
                LogEngine.WriteLog(
                    Configuration.EngineName,
                    $"Error in {MethodBase.GetCurrentMethod().Name}",
                    Constant.DefconOne,
                    Constant.TaskCategoriesError,
                    ex,
                    EventLogEntryType.Error);
            }
        }