Exemplo n.º 1
0
		public static IClientBuilder UseQueueSuffix(this IClientBuilder builder, QueueSuffixOptions options = null)
		{
			if (options == null)
			{
				builder.Register(pipe => pipe.Use<QueueSuffixMiddleware>());
			}
			else
			{
				builder.Register(pipe => pipe.Use<QueueSuffixMiddleware>(options));
			}
			return builder;
		}
Exemplo n.º 2
0
        public static IClientBuilder UseHttpContext(this IClientBuilder builder)
        {
#if NET451
            builder.Register(p => p
                             .Use <NetFxHttpContextMiddleware>()
                             );
#endif
#if NETSTANDARD1_6
            builder.Register(
                p => p.Use <AspNetCoreHttpContextMiddleware>(),
                p => p.AddSingleton <Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>()
                );
#endif
            return(builder);
        }
Exemplo n.º 3
0
        public static IClientBuilder UseJaeger(this IClientBuilder builder, ITracer tracer)
        {
            builder.Register(pipe =>
                             pipe.Use <JaegerStagedMiddleware>(tracer));

            return(builder);
        }
Exemplo n.º 4
0
 /// <summary>
 /// Replaces the default serializer with Protobuf.
 /// </summary>
 public static IClientBuilder UseProtobuf(this IClientBuilder builder)
 {
     builder.Register(
         pipe: p => {},
         ioc: di => di.AddSingleton <ISerializer, ProtobufSerializer>());
     return(builder);
 }
Exemplo n.º 5
0
 /// <summary>
 /// Replaces the default serializer with MessagePack.
 /// </summary>
 public static IClientBuilder UseMessagePack(this IClientBuilder builder, MessagePackFormat format = MessagePackFormat.Normal)
 {
     builder.Register(
         pipe: p => { },
         ioc: di => di.AddSingleton <ISerializer, MessagePackSerializerWorker>(resolver => new MessagePackSerializerWorker(format)));
     return(builder);
 }
Exemplo n.º 6
0
 /// <summary>
 /// Replaces the default serializer with ZeroFormatter.
 /// </summary>
 public static IClientBuilder UseZeroFormatter(this IClientBuilder builder)
 {
     builder.Register(
         pipe: p => { },
         ioc: di => di.AddSingleton <ISerializer, ZeroFormatterSerializerWorker>());
     return(builder);
 }
Exemplo n.º 7
0
        public static IClientBuilder UseHttpContext(this IClientBuilder builder)
        {
            builder.Register(
                p => p.Use <AspNetCoreHttpContextMiddleware>(),
                p => p.AddSingleton <Microsoft.AspNetCore.Http.IHttpContextAccessor, Microsoft.AspNetCore.Http.HttpContextAccessor>()
                );

            return(builder);
        }
 public static IClientBuilder UseContextForwarding(this IClientBuilder builder)
 {
     builder.Register(
         pipe => pipe
         .Use <PublishForwardingMiddleware>()
         .Use <ConsumeForwardingMiddleware>(),
         ioc => ioc
         .AddSingleton <IMessageContextRepository, MessageContextRepository>());
     return(builder);
 }
Exemplo n.º 9
0
        public static IClientBuilder UseMessageContext <TMessageContext>(this IClientBuilder builder, Func <IPipeContext, TMessageContext> createFunc)
        {
            Func <IPipeContext, object> genericCreateFunc = context => createFunc(context);

            builder.Register(pipe => pipe.Use <HeaderSerializationMiddleware>(new HeaderSerializationOptions
            {
                HeaderKeyFunc    = context => PropertyHeaders.Context,
                RetrieveItemFunc = context => context.GetMessageContext(),
                CreateItemFunc   = genericCreateFunc
            }));
            return(builder);
        }
Exemplo n.º 10
0
 public static IClientBuilder UseRetryLater(this IClientBuilder builder)
 {
     builder.Register(
         pipe => pipe
         .Use <RetryLaterMiddleware>()
         .Use <RetryInformationExtractionMiddleware>(),
         ioc => ioc
         .AddSingleton <IRetryInformationHeaderUpdater, RetryInformationHeaderUpdater>()
         .AddSingleton <IRetryInformationProvider, RetryInformationProvider>()
         );
     return(builder);
 }
Exemplo n.º 11
0
 /// <summary>
 /// Registers dependencies for the StateMachine operation.
 ///
 /// StateMachine models are stored in-memory, but can
 /// be changed by registrating functions for get, add and update.
 /// The execution is only exclusive in the process. If usesd in
 /// a distributed environment, consider changing this by
 /// register an own execute func.
 /// </summary>
 /// <param name="builder">The client builder</param>
 /// <param name="get">Get for model (repo)</param>
 /// <param name="addOrUpdate">Add or update (repo)</param>
 /// <param name="execute">Method to ensure exclusive execution</param>
 /// <returns></returns>
 public static IClientBuilder UseStateMachine(
     this IClientBuilder builder,
     Func <Guid, Task <Model> > get = null,
     Func <Model, Task> addOrUpdate = null,
     Func <Guid, Func <Task>, CancellationToken, Task> execute = null)
 {
     builder.Register(
         pipe => {},
         ioc => ioc
         .AddSingleton <IGlobalLock>(new GlobalLock(execute))
         .AddSingleton <IModelRepository>(new ModelRepository(get, addOrUpdate))
         .AddTransient <IStateMachineActivator, StateMachineActivator>(resolver => new StateMachineActivator(resolver.GetService <IModelRepository>(), resolver))
         );
     return(builder);
 }
Exemplo n.º 12
0
 public static IClientBuilder UsePolly(this IClientBuilder builder, PolicyOptions options)
 {
     builder.Register(
         pipe => pipe
         .Use <PolicyMiddleware>(options)
         .Replace <QueueDeclareMiddleware, Enrichers.Polly.Middleware.QueueDeclareMiddleware>(argsFunc: oldArgs => oldArgs)
         .Replace <ExchangeDeclareMiddleware, Enrichers.Polly.Middleware.ExchangeDeclareMiddleware>(argsFunc: oldArgs => oldArgs)
         .Replace <QueueBindMiddleware, Enrichers.Polly.Middleware.QueueBindMiddleware>(argsFunc: oldArgs => oldArgs)
         .Replace <ConsumerCreationMiddleware, Enrichers.Polly.Middleware.ConsumerCreationMiddleware>(argsFunc: oldArgs => oldArgs)
         .Replace <BasicPublishMiddleware, Enrichers.Polly.Middleware.BasicPublishMiddleware>(argsFunc: oldArgs => oldArgs)
         .Replace <ExplicitAckMiddleware, Enrichers.Polly.Middleware.ExplicitAckMiddleware>(argsFunc: oldArgs => oldArgs)
         .Replace <PooledChannelMiddleware, Enrichers.Polly.Middleware.PooledChannelMiddleware>(argsFunc: oldArgs => oldArgs)
         .Replace <TransientChannelMiddleware, Enrichers.Polly.Middleware.TransientChannelMiddleware>(argsFunc: oldArgs => oldArgs)
         .Replace <HandlerInvocationMiddleware, Enrichers.Polly.Middleware.HandlerInvocationMiddleware>(argsFunc: oldArgs => oldArgs),
         ioc => ioc
         .AddSingleton <IChannelFactory, RawRabbit.Enrichers.Polly.Services.ChannelFactory>()
         .AddSingleton(options.ConnectionPolicies));
     return(builder);
 }
Exemplo n.º 13
0
 public static IClientBuilder UseAttributeRouting(this IClientBuilder builder, ConsumeAttributeOptions consume = null, ProduceAttributeOptions produce = null)
 {
     if (consume == null)
     {
         consume = new ConsumeAttributeOptions
         {
             MessageTypeFunc = context => context.Get <Type>(IncommingMessageType) ?? context.Get <Type>(PipeKey.MessageType)
         };
     }
     if (produce == null)
     {
         produce = new ProduceAttributeOptions
         {
             MessageTypeFunc = context => context.Get <Type>(OutgoingMessageType) ?? context.Get <Type>(PipeKey.MessageType)
         };
     }
     builder.Register(pipe => pipe
                      .Use <ConsumeAttributeMiddleware>(consume)
                      .Use <ProduceAttributeMiddleware>(produce));
     return(builder);
 }
        public static IClientBuilder UseGlobalExecutionId(this IClientBuilder builder)
        {
            builder.Register(pipe => pipe
                             // Pulisher
                             .Use <AppendGlobalExecutionIdMiddleware>()
                             .Use <ExecutionIdRoutingMiddleware>()
                             .Use <PublishHeaderAppenderMiddleware>()

                             // Subscriber
                             .Use <WildcardRoutingKeyMiddleware>()

                             // Message Received
                             .Use <HeaderDeserializationMiddleware>(new HeaderDeserializationOptions
            {
                HeaderKeyFunc     = c => PropertyHeaders.GlobalExecutionId,
                HeaderTypeFunc    = c => typeof(string),
                ContextSaveAction = (ctx, id) => ctx.Properties.TryAdd(PipeKey.GlobalExecutionId, id)
            })
                             .Use <PersistGlobalExecutionIdMiddleware>()
                             );
            return(builder);
        }
 public static IClientBuilder UseExtensionRetryLater(this IClientBuilder builder)
 {
     builder.UseAttributeRouting().UseRetryLater().Register(
         pipe: p => {
         p.Replace <RetryLaterMiddleware, ExtensionRetryLaterMiddleware>(args: new RetryLaterOptions()
         {
             DeliveryArgsFunc = pipeContext => {
                 var deliveryEventArgs = pipeContext.GetDeliveryEventArgs();
                 //var consumerConfiguration = pipeContext.GetConsumerConfiguration();
                 //if (consumerConfiguration != null && consumerConfiguration.Queue != null)
                 //{
                 //	deliveryEventArgs.RoutingKey = consumerConfiguration.Queue.Name;
                 //	deliveryEventArgs.Exchange = consumerConfiguration.Queue.Name;
                 //}
                 return(deliveryEventArgs);
             }
         });
     });
     builder.Register(pipe: p => {
         p.Replace <HeaderDeserializationMiddleware, HeaderDeserializationMiddleware>(args: new HeaderDeserializationOptions()
         {
             HeaderKeyFunc     = c => PropertyHeaders.Context,
             HeaderTypeFunc    = c => c.GetMessageContextType(),
             ContextSaveAction = (pipeCtx, msgCtx) => pipeCtx.Properties.TryAdd(PipeKey.MessageContext, msgCtx),
             DeliveryArgsFunc  = pipeContext => {
                 var deliveryEventArgs = pipeContext.GetDeliveryEventArgs();
                 //增加这个是因为RawRabbit中HeaderDeserializationMiddleware有一个BUG,在Headers==null的时候会引发一个异常
                 if (deliveryEventArgs.BasicProperties.Headers == null)
                 {
                     deliveryEventArgs.BasicProperties.Headers = new Dictionary <string, object>();
                 }
                 return(deliveryEventArgs);
             }
         });
     });
     return(builder);
 }
Exemplo n.º 16
0
        private static IClientBuilder ProcessUniqueMessages(this IClientBuilder clientBuilder)
        {
            clientBuilder.Register(c => c.Use <ProcessUniqueMessagesMiddleware>());

            return(clientBuilder);
        }
Exemplo n.º 17
0
        private static IClientBuilder UpdateRetryInfo(this IClientBuilder clientBuilder)
        {
            clientBuilder.Register(c => c.Use <RetryStagedMiddleware>());

            return(clientBuilder);
        }