/// <summary>
        /// Convert message off the wire from byte[] into a concrete implementation of IIntegrationMessage
        /// delegates to custom extractors and defaults to Json deserialization
        /// </summary>
        private IIntegrationMessage _extractMessage(byte[] messageData, MessageTypeProperties props)
        {
            IIntegrationMessage message;

            if (props.HasCustomExtractor)
            {
                IMessageExtractor extractor = null;
                if (_messageExtractorCache.ContainsKey(props.MessageTypeIdentifier))
                {
                    extractor = _messageExtractorCache[props.MessageTypeIdentifier];
                }
                else
                {
                    extractor = (IMessageExtractor)Activator.CreateInstance(props.Type, true);
                    _messageExtractorCache.Add(props.MessageTypeIdentifier, extractor);
                }
                message = extractor.Extract(messageData);
            }
            else
            {
                //by default the message is json and will be deserialized to the type with a matching MessageTypeIdentifier property:"MessageType"
                var json = Encoding.UTF8.GetString(messageData);
                message = (IIntegrationMessage)JsonConvert.DeserializeObject(json, props.Type, _serializerSettings);
            }
            return(message);
        }
示例#2
0
        /// <summary>
        /// Register a named entity type by defining the <see cref="Actor.Props"/> of the entity actor and
        /// functions to extract entity and shard identifier from messages. The <see cref="Sharding.ShardRegion"/>
        /// actor for this type can later be retrieved with the <see cref="ShardRegion"/> method.
        /// </summary>
        /// <param name="typeName">The name of the entity type</param>
        /// <param name="entityProps">
        /// The <see cref="Actor.Props"/> of the entity actors that will be created by the <see cref="Sharding.ShardRegion"/>
        /// </param>
        /// <param name="settings">Configuration settings, see <see cref="ClusterShardingSettings"/></param>
        /// <param name="messageExtractor">
        /// Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message.
        /// </param>
        /// <param name="allocationStrategy">Possibility to use a custom shard allocation and rebalancing logic</param>
        /// <param name="handOffMessage">
        /// The message that will be sent to entities when they are to be stopped for a rebalance or
        /// graceful shutdown of a <see cref="Sharding.ShardRegion"/>, e.g. <see cref="PoisonPill"/>.
        /// </param>
        /// <returns>The actor ref of the <see cref="Sharding.ShardRegion"/> that is to be responsible for the shard.</returns>
        public Task <IActorRef> StartAsync(string typeName, Props entityProps, ClusterShardingSettings settings,
                                           IMessageExtractor messageExtractor, IShardAllocationStrategy allocationStrategy, object handOffMessage)
        {
            ExtractEntityId extractEntityId = messageExtractor.ToExtractEntityId();
            ExtractShardId  extractShardId  = messageExtractor.ShardId;

            return(StartAsync(typeName, entityProps, settings, extractEntityId, extractShardId, allocationStrategy, handOffMessage));
        }
示例#3
0
        /// <summary>
        /// Register a named entity type by defining the <see cref="Actor.Props"/> of the entity actor and
        /// functions to extract entity and shard identifier from messages. The <see cref="Sharding.ShardRegion"/>
        /// actor for this type can later be retrieved with the <see cref="ShardRegion"/> method.
        /// </summary>
        /// <param name="typeName">The name of the entity type</param>
        /// <param name="entityProps">
        /// The <see cref="Actor.Props"/> of the entity actors that will be created by the <see cref="Sharding.ShardRegion"/>
        /// </param>
        /// <param name="settings">Configuration settings, see <see cref="ClusterShardingSettings"/></param>
        /// <param name="messageExtractor">
        /// Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message.
        /// </param>
        /// <param name="allocationStrategy">Possibility to use a custom shard allocation and rebalancing logic</param>
        /// <param name="handOffMessage">
        /// The message that will be sent to entities when they are to be stopped for a rebalance or
        /// graceful shutdown of a <see cref="Sharding.ShardRegion"/>, e.g. <see cref="PoisonPill"/>.
        /// </param>
        /// <returns>The actor ref of the <see cref="Sharding.ShardRegion"/> that is to be responsible for the shard.</returns>
        public Task <IActorRef> StartAsync(string typeName, Props entityProps, ClusterShardingSettings settings,
                                           IMessageExtractor messageExtractor, IShardAllocationStrategy allocationStrategy, object handOffMessage)
        {
            IdExtractor   idExtractor   = messageExtractor.ToIdExtractor();
            ShardResolver shardResolver = messageExtractor.ShardId;

            return(StartAsync(typeName, entityProps, settings, idExtractor, shardResolver, allocationStrategy, handOffMessage));
        }
示例#4
0
        /// <summary>
        /// Register a named entity type `ShardRegion` on this node that will run in proxy only mode, i.e.it will
        /// delegate messages to other `ShardRegion` actors on other nodes, but not host any entity actors itself.
        /// The <see cref="Sharding.ShardRegion"/>  actor for this type can later be retrieved with the
        /// <see cref="ShardRegion"/>  method.
        /// </summary>
        /// <param name="typeName">The name of the entity type.</param>
        /// <param name="role">
        /// Specifies that this entity type is located on cluster nodes with a specific role.
        /// If the role is not specified all nodes in the cluster are used.
        /// </param>
        /// <param name="messageExtractor">
        /// Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message.
        /// </param>
        /// <returns>The actor ref of the <see cref="Sharding.ShardRegion"/> that is to be responsible for the shard.</returns>
        public Task <IActorRef> StartProxyAsync(string typeName, string role, IMessageExtractor messageExtractor)
        {
            IdExtractor extractEntityId = msg =>
            {
                var entityId      = messageExtractor.EntityId(msg);
                var entityMessage = messageExtractor.EntityMessage(msg);
                return(Tuple.Create(entityId, entityMessage));
            };

            return(StartProxyAsync(typeName, role, extractEntityId, messageExtractor.ShardId));
        }
示例#5
0
 protected void RegisterExtractor(IMessageExtractor extractor)
 {
     if (!_messageExtractorRegister.ContainsKey(extractor.ExtractorForType))
     {
         _messageExtractorRegister.Add(extractor.ExtractorForType, extractor);
     }
     else
     {
         _messageExtractorRegister[extractor.ExtractorForType] = extractor;
     }
 }
示例#6
0
        /// <summary>
        /// Register a named entity type `ShardRegion` on this node that will run in proxy only mode, i.e.it will
        /// delegate messages to other `ShardRegion` actors on other nodes, but not host any entity actors itself.
        /// The <see cref="Sharding.ShardRegion"/>  actor for this type can later be retrieved with the
        /// <see cref="ShardRegion"/>  method.
        /// </summary>
        /// <param name="typeName">The name of the entity type.</param>
        /// <param name="role">
        /// Specifies that this entity type is located on cluster nodes with a specific role.
        /// If the role is not specified all nodes in the cluster are used.
        /// </param>
        /// <param name="messageExtractor">
        /// Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message.
        /// </param>
        /// <returns>The actor ref of the <see cref="Sharding.ShardRegion"/> that is to be responsible for the shard.</returns>
        public IActorRef StartProxy(string typeName, string role, IMessageExtractor messageExtractor)
        {
            Tuple <EntityId, Msg> extractEntityId(Msg msg)
            {
                var entityId      = messageExtractor.EntityId(msg);
                var entityMessage = messageExtractor.EntityMessage(msg);

                return(Tuple.Create(entityId, entityMessage));
            };

            return(StartProxy(typeName, role, extractEntityId, messageExtractor.ShardId));
        }
示例#7
0
 /// <summary>
 /// Register a named entity type by defining the <see cref="Actor.Props"/> of the entity actor and
 /// functions to extract entity and shard identifier from messages. The <see cref="Sharding.ShardRegion"/>
 /// actor for this type can later be retrieved with the <see cref="ShardRegion"/> method.
 /// </summary>
 /// <param name="typeName">The name of the entity type</param>
 /// <param name="entityProps">
 /// The <see cref="Actor.Props"/> of the entity actors that will be created by the <see cref="Sharding.ShardRegion"/>
 /// </param>
 /// <param name="settings">Configuration settings, see <see cref="ClusterShardingSettings"/></param>
 /// <param name="messageExtractor">
 /// Functions to extract the entity id, shard id, and the message to send to the entity from the incoming message.
 /// </param>
 /// <returns>The actor ref of the <see cref="Sharding.ShardRegion"/> that is to be responsible for the shard.</returns>
 public Task <IActorRef> StartAsync(string typeName, Props entityProps, ClusterShardingSettings settings,
                                    IMessageExtractor messageExtractor)
 {
     return(StartAsync(typeName,
                       entityProps,
                       settings,
                       messageExtractor,
                       new LeastShardAllocationStrategy(
                           Settings.TunningParameters.LeastShardAllocationRebalanceThreshold,
                           Settings.TunningParameters.LeastShardAllocationMaxSimultaneousRebalance),
                       PoisonPill.Instance));
 }
示例#8
0
        public void Init(string name, string ip, int port, int send_timeout, bool keepalive,
                         IMessageExtractor extractor, IMessageEncoder encoder, bool compress)
        {
            m_Name        = name;
            m_RemoteIP    = IPAddress.Parse(ip);
            m_RemotePort  = port;
            m_SendTimeOut = send_timeout;
            m_bCompress   = compress;

            m_bKeepAlive = keepalive;

            m_Extractor = extractor;
            m_Encoder   = encoder;
        }
示例#9
0
        /// <summary>
        /// TBD
        /// </summary>
        /// <param name="self">TBD</param>
        /// <returns>TBD</returns>
        public static ExtractEntityId ToExtractEntityId(this IMessageExtractor self)
        {
            ExtractEntityId extractEntityId = msg =>
            {
                if (self.EntityId(msg) != null)
                {
                    return(Tuple.Create(self.EntityId(msg), self.EntityMessage(msg)));
                }
                //TODO: should we really use tuples?

                return(null);
            };

            return(extractEntityId);
        }
示例#10
0
        public static IdExtractor ToIdExtractor(this IMessageExtractor self)
        {
            IdExtractor idExtractor = msg =>
            {
                if (self.EntityId(msg) != null)
                {
                    return(Tuple.Create(self.EntityId(msg), self.EntityMessage(msg)));
                }
                //TODO: should we really use tuples?

                return(null);
            };

            return(idExtractor);
        }
示例#11
0
        protected MessageProcessorBase(IAmazonS3 s3Client = null, ILoggerFactory loggerFactory = null)
        {
            _s3Client = s3Client ?? new AmazonS3Client(RegionEndpoint.GetBySystemName(Environment.GetEnvironmentVariable("AWS_REGION")));

            if (typeof(TEventType) == typeof(SQSEvent))
            {
                _messageExtractor = new SQSMessageExtractor <TMessageType>();
            }
            else if (typeof(TEventType) == typeof(SNSEvent))
            {
                _messageExtractor = new SNSMessageExtractor <TMessageType>();
            }
            else if (typeof(TEventType) == typeof(KinesisEvent))
            {
                _messageExtractor = new KinesisMessageExtractor <TMessageType>();
            }

            _deprecatedExtractor = default;

            _logger = loggerFactory == null ? NullLogger.Instance : loggerFactory.CreateLogger(GetType());
        }
示例#12
0
        /// <summary>
        /// ClientCommunicator构造函数
        /// </summary>
        /// <param name="clientid">客户端ID</param>
        /// <param name="client">客户端的TCP实体</param>
        /// <param name="filter">报文过滤器</param>
        public Communicator(ICommer parent_commer, long clientid, Socket client, ICommandInterpreter intepreter,
                            IMessageExtractor extractor, IMessageEncoder encoder, bool compress)
        {
            m_ParentCommer = parent_commer;
            m_ClientID     = clientid;
            m_Client       = client;
            m_ClientInfo   = client.RemoteEndPoint as IPEndPoint;

            m_Interpreter = intepreter;

            if (m_Interpreter != null)
            {
                m_Interpreter.CommunicatorObj = this;
            }

            m_bCompress = compress;

            m_Extractor            = extractor;
            m_Extractor.Compressed = compress;

            m_Encoder           = encoder;
            onConnectionBroken += new ConnectionBrokenHandler(ClientCommunicator_onConnectionBroken);
        }
 protected void RegisterExtractor(IMessageExtractor <SQSMessageEnvelope <TMessageType> > extractor)
 {
     _messageExtractor = extractor;
 }
示例#14
0
 protected void RegisterExtractor(IMessageExtractor extractor)
 {
     _deprecatedExtractor = extractor;
 }
示例#15
0
 protected void RegisterExtractor(IMessageExtractor <TMessageType> extractor)
 {
     _messageExtractor = extractor;
 }
示例#16
0
 protected SNSMessageMessageProcessorBase(IAmazonS3 s3Client = null, ILoggerFactory loggerFactory = null) : base(s3Client, loggerFactory)
 {
     _messageExtractor = new SNSMessageExtractor <TMessageType>();
 }
示例#17
0
 public LoggingMessageExtractorDecorator(IMessageExtractor messageExtractor, ILoggingAdapter adapter)
 {
     _adapter          = adapter;
     _messageExtractor = messageExtractor;
 }
 public LoggingMessageExtractorDecorator(IMessageExtractor messageExtractor, ILoggingAdapter adapter)
 {
     _adapter = adapter;
     _messageExtractor = messageExtractor;
 }