Ejemplo n.º 1
0
        public static ChannelPipelineIncoming AddChannelIncoming(this MicroservicePipeline pipeline
                                                                 , string channelId
                                                                 , string description = null
                                                                 , IEnumerable <ListenerPartitionConfig> partitions = null
                                                                 , IBoundaryLogger bLogger = null
                                                                 , IEnumerable <ResourceProfile> resourceProfiles = null
                                                                 , bool internalOnly = false
                                                                 , Action <ChannelPipelineIncoming, Channel> assign = null
                                                                 )
        {
            var channel = pipeline.Service.RegisterChannel(new Channel(channelId, ChannelDirection.Incoming, description, bLogger, internalOnly));

            if (partitions != null)
            {
                channel.Partitions = partitions.ToList();
            }
            if (resourceProfiles != null)
            {
                channel.ResourceProfiles = resourceProfiles.ToList();
            }

            var cpipe = new ChannelPipelineIncoming(pipeline, channel);

            assign?.Invoke(cpipe, cpipe.Channel);

            return(cpipe);
        }
Ejemplo n.º 2
0
        public static MicroservicePipeline AddCommand <C>(this MicroservicePipeline pipeline
                                                          , C command
                                                          , Action <C> assignment = null
                                                          , ChannelPipelineIncoming channelIncoming = null
                                                          , ChannelPipelineOutgoing channelResponse = null
                                                          , ChannelPipelineIncoming channelMasterJobNegotiationIncoming = null
                                                          , ChannelPipelineOutgoing channelMasterJobNegotiationOutgoing = null
                                                          )
            where C : ICommand
        {
            if (channelIncoming != null && command.ChannelIdAutoSet)
            {
                command.ChannelId = channelIncoming.Channel.Id;
            }

            if (channelResponse != null && command.ResponseChannelIdAutoSet)
            {
                command.ResponseChannelId = channelResponse.Channel.Id;
            }

            if (channelMasterJobNegotiationIncoming != null && command.MasterJobNegotiationChannelIdAutoSet)
            {
                command.MasterJobNegotiationChannelIdIncoming = channelMasterJobNegotiationIncoming.Channel.Id;
            }

            if (channelMasterJobNegotiationOutgoing != null && command.MasterJobNegotiationChannelIdAutoSet)
            {
                command.MasterJobNegotiationChannelIdOutgoing = channelMasterJobNegotiationOutgoing.Channel.Id;
            }

            assignment?.Invoke(command);
            pipeline.Service.RegisterCommand(command);
            return(pipeline);
        }
        public static ChannelPipelineIncoming AssignPriorityPartition(this ChannelPipelineIncoming pipeline, Func <IEnvironmentConfiguration, Channel, ListenerPartitionConfig> creator)
        {
            var config = creator(pipeline.Pipeline.Configuration, pipeline.Channel);

            AddPriorityPartition <ListenerPartitionConfig>(pipeline, config);
            return(pipeline);
        }
Ejemplo n.º 4
0
        public static ChannelPipelineIncoming AttachListener(this ChannelPipelineIncoming cpipe
                                                             , IListener listener
                                                             , bool setFromChannelProperties = true
                                                             )
        {
            if (cpipe.Channel.InternalOnly)
            {
                throw new ChannelInternalOnlyException(cpipe.Channel.Id, cpipe.Channel.Direction);
            }

            if (setFromChannelProperties && listener.ChannelId != cpipe.Channel.Id)
            {
                throw new ChannelIdMismatchException(cpipe.Channel.Id, cpipe.Channel.Direction, listener.ChannelId);
            }

            if (setFromChannelProperties)
            {
                listener.BoundaryLogger     = cpipe.Channel.BoundaryLogger;
                listener.PriorityPartitions = cpipe.Channel.Partitions.Cast <ListenerPartitionConfig>().ToList();
                listener.ResourceProfiles   = cpipe.Channel.ResourceProfiles;
            }

            cpipe.Pipeline.Service.RegisterListener(listener);

            return(cpipe);
        }
        /// <summary>
        /// Use this pipeline command to add a channel to a Microservice.
        /// </summary>
        /// <param name="pipeline">The pipeline.</param>
        /// <param name="channelId">The channel id.</param>
        /// <param name="description">A description of what the channel is used for.</param>
        /// <param name="partitions">The supported partition levels for the channel. If null, this will be set to Priority 0 and 1.</param>
        /// <param name="boundaryLoggingEnabled">Use this flag to override the default boundary logging settings for the Microservice.</param>
        /// <param name="resourceProfiles">The resource profiles that should be used in the polling logic to reduce or stop incoming messages.</param>
        /// <param name="internalOnly">Set this flag to true if you don't wish to attach any external listeners to this channel, i.e. internal only.</param>
        /// <param name="assign"></param>
        /// <param name="autosetPartition01">This method automatically sets the default priority 0 and 1 partitions for the channel.</param>
        /// <returns>The original pipeline.</returns>
        public static IPipelineChannelIncoming <P> AddChannelIncoming <P>(this P pipeline
                                                                          , string channelId
                                                                          , string description = null
                                                                          , IEnumerable <ListenerPartitionConfig> partitions = null
                                                                          , bool?boundaryLoggingEnabled = null
                                                                          , IEnumerable <ResourceProfile> resourceProfiles = null
                                                                          , bool internalOnly = false
                                                                          , Action <IPipelineChannelIncoming <P>, Channel> assign = null
                                                                          , bool autosetPartition01 = true
                                                                          )
            where P : IPipeline
        {
            var channel = pipeline.ToMicroservice().Communication.RegisterChannel(
                new Channel(channelId, ChannelDirection.Incoming, description, boundaryLoggingEnabled, internalOnly));

            if (partitions == null && autosetPartition01)
            {
                partitions = ListenerPartitionConfig.Init(0, 1);
            }

            channel.Partitions = partitions?.ToList();

            if (resourceProfiles != null)
            {
                channel.ResourceProfiles = resourceProfiles?.ToList();
            }

            var cpipe = new ChannelPipelineIncoming <P>(pipeline, channel);

            assign?.Invoke(cpipe, cpipe.Channel);

            return(cpipe);
        }
Ejemplo n.º 6
0
        public static ChannelPipelineIncoming AddCommand <C>(this ChannelPipelineIncoming cpipe, Action <C> assign = null)
            where C : ICommand, new()
        {
            var command = new C();

            assign?.Invoke(command);
            return(cpipe.AddCommand(command));
        }
Ejemplo n.º 7
0
        public static ChannelPipelineIncoming Inspect(this ChannelPipelineIncoming pipeline
                                                      , Action <IMicroservice> msAssign             = null
                                                      , Action <IEnvironmentConfiguration> cfAssign = null
                                                      , Action <Channel> cnAssign = null)
        {
            msAssign?.Invoke(pipeline.Pipeline.Service);
            cfAssign?.Invoke(pipeline.Pipeline.Configuration);
            cnAssign?.Invoke(pipeline.Channel);

            return(pipeline);
        }
Ejemplo n.º 8
0
        public static ChannelPipelineIncoming AppendResourceProfile(this ChannelPipelineIncoming cpipe
                                                                    , IEnumerable <ResourceProfile> profiles)
        {
            if (profiles == null)
            {
                throw new ArgumentNullException("profiles cannot be null");
            }

            profiles.ForEach((p) => cpipe.Channel.ResourceProfiles.Add(p));

            return(cpipe);
        }
Ejemplo n.º 9
0
        public static ChannelPipelineIncoming AppendResourceProfile(this ChannelPipelineIncoming cpipe
                                                                    , string profileName
                                                                    , Action <ResourceProfile> action = null)
        {
            if (string.IsNullOrEmpty(profileName))
            {
                throw new ArgumentNullException("profileName cannot be null or empty");
            }

            cpipe.AppendResourceProfile((c) => new ResourceProfile(profileName), action);

            return(cpipe);
        }
Ejemplo n.º 10
0
        public static ChannelPipelineIncoming AppendResourceProfile(this ChannelPipelineIncoming cpipe
                                                                    , ResourceProfile profile
                                                                    , Action <ResourceProfile> action = null)
        {
            if (profile == null)
            {
                throw new ArgumentNullException("profile cannot be null");
            }

            cpipe.AppendResourceProfile((c) => profile, action);

            return(cpipe);
        }
Ejemplo n.º 11
0
        public static ChannelPipelineIncoming AddCommand <C>(this ChannelPipelineIncoming cpipe
                                                             , Func <IEnvironmentConfiguration, C> creator
                                                             , Action <C> assignment = null
                                                             , ChannelPipelineOutgoing channelResponse = null
                                                             , ChannelPipelineIncoming channelMasterJobNegotiationIncoming = null
                                                             , ChannelPipelineOutgoing channelMasterJobNegotiationOutgoing = null
                                                             )
            where C : ICommand
        {
            cpipe.Pipeline.AddCommand(creator, assignment, cpipe, channelResponse, channelMasterJobNegotiationIncoming, channelMasterJobNegotiationOutgoing);

            return(cpipe);
        }
Ejemplo n.º 12
0
        public static ChannelPipelineIncoming AddCommand <C>(this ChannelPipelineIncoming cpipe
                                                             , C command
                                                             , Action <C> assignment = null
                                                             , ChannelPipelineOutgoing channelResponse = null
                                                             , ChannelPipelineIncoming channelMasterJobNegotiationIncoming = null
                                                             , ChannelPipelineOutgoing channelMasterJobNegotiationOutgoing = null
                                                             )
            where C : ICommand
        {
            cpipe.Pipeline.AddCommand(command, assignment, cpipe, channelResponse, channelMasterJobNegotiationIncoming, channelMasterJobNegotiationOutgoing);

            return(cpipe);
        }
Ejemplo n.º 13
0
        public static MicroservicePipeline AddCommand <C>(this MicroservicePipeline pipeline
                                                          , Func <IEnvironmentConfiguration, C> creator
                                                          , Action <C> assignment = null
                                                          , ChannelPipelineIncoming channelIncoming = null
                                                          , ChannelPipelineOutgoing channelResponse = null
                                                          , ChannelPipelineIncoming channelMasterJobNegotiationIncoming = null
                                                          , ChannelPipelineOutgoing channelMasterJobNegotiationOutgoing = null
                                                          )
            where C : ICommand
        {
            var command = creator(pipeline.Configuration);

            return(pipeline.AddCommand(command, assignment, channelIncoming, channelResponse, channelMasterJobNegotiationIncoming));
        }
Ejemplo n.º 14
0
        public static ChannelPipelineIncoming AttachListener <S>(this ChannelPipelineIncoming cpipe
                                                                 , Func <IEnvironmentConfiguration, S> creator
                                                                 , Action <S> action             = null
                                                                 , bool setFromChannelProperties = true
                                                                 )
            where S : IListener
        {
            var listener = creator(cpipe.Pipeline.Configuration);

            action?.Invoke(listener);

            cpipe.AttachListener(listener, setFromChannelProperties);

            return(cpipe);
        }
Ejemplo n.º 15
0
        public static ChannelPipelineIncoming AppendResourceProfile(this ChannelPipelineIncoming cpipe
                                                                    , Func <IEnvironmentConfiguration, ResourceProfile> creator
                                                                    , Action <ResourceProfile> action = null)
        {
            if (creator == null)
            {
                throw new ArgumentNullException("creator cannot be null");
            }

            var profile = creator(cpipe.Pipeline.Configuration);

            action?.Invoke(profile);

            cpipe.Channel.ResourceProfiles.Add(profile);

            return(cpipe);
        }
Ejemplo n.º 16
0
        public static ChannelPipelineIncoming AssignPriorityPartition(this ChannelPipelineIncoming pipeline, IEnumerable <ListenerPartitionConfig> config)
        {
            config?.ForEach((p) => pipeline.AssignPriorityPartition(p));

            return(pipeline);
        }
Ejemplo n.º 17
0
        public static ChannelPipelineIncoming AssignPriorityPartition(this ChannelPipelineIncoming pipeline, params int[] init)
        {
            ListenerPartitionConfig.Init(init).ForEach((p) => AddPriorityPartition <ListenerPartitionConfig>(pipeline, p));

            return(pipeline);
        }
Ejemplo n.º 18
0
 //Incoming
 public static ChannelPipelineIncoming AssignPriorityPartition(this ChannelPipelineIncoming pipeline, ListenerPartitionConfig config)
 {
     AddPriorityPartition <ListenerPartitionConfig>(pipeline, config);
     return(pipeline);
 }