public MassTransitTriggerListener(IMassTransitListenerFactory listenerFactory,
                                   string busName,
                                   string queueName,
                                   TriggerParameterMode triggerParameterMode,
                                   SessionUsage sessionUsage,
                                   ITriggeredFunctionExecutor contextExecutor)
 {
     BusControl = listenerFactory.GetListener <TMessage>(busName, queueName, triggerParameterMode, sessionUsage, contextExecutor);
 }
 public MassTransitTriggerBinding(IMassTransitListenerFactory listenerFactory, string busName, string queueName, TriggerParameterMode triggerParameterMode, SessionUsage sessionUsage, ParameterInfo parameter)
 {
     MassTransitListenerFactory = listenerFactory;
     BusName              = busName;
     QueueName            = queueName;
     TriggerParameterMode = triggerParameterMode;
     Parameter            = parameter;
     SessionUsage         = sessionUsage;
     _bindingDataContract = GetBindingDataContract(parameter);
 }
 public MassTransitTriggerBinding(IMassTransitListenerFactory listenerFactory,
                                  string busName,
                                  string queueName,
                                  TriggerParameterMode triggerParameterMode,
                                  SessionUsage sessionUsage,
                                  ParameterInfo parameterInfo)
 {
     MassTransitListenerFactory = listenerFactory;
     BusName              = busName;
     QueueName            = queueName;
     TriggerParameterMode = triggerParameterMode;
     ParameterInfo        = parameterInfo;
     SessionUsage         = sessionUsage;
     _bindingDataContract = new Dictionary <string, Type>();
 }
        private static async Task HandleMessageAsync <TMessage>(
            ConsumeContext <TMessage> context, TriggerParameterMode triggerParameterMode, ITriggeredFunctionExecutor contextExecutor)
            where TMessage : class
        {
            var input = new TriggeredFunctionData
            {
                TriggerValue   = ConvertToParameterType(context, triggerParameterMode),
                TriggerDetails = new Dictionary <string, string>()
            };

            var result = await contextExecutor
                         .TryExecuteAsync(input, context.CancellationToken)
                         .ConfigureAwait(false);

            if (!result.Succeeded)
            {
                throw result.Exception;
            }
        }
Exemplo n.º 5
0
 private static MassTransitTriggerBinding <TMessage> BuildBinding <TMessage>(
     IMassTransitListenerFactory listenerFactory, string busName, string queueName, TriggerParameterMode triggerParameterMode, SessionUsage sessionUsage, ParameterInfo parameter)
     where TMessage : class
 {
     return(new MassTransitTriggerBinding <TMessage>(listenerFactory, busName, queueName, triggerParameterMode, sessionUsage, parameter));
 }
        private static object ConvertToParameterType <TMessage>(ConsumeContext <TMessage> context, TriggerParameterMode triggerParameterMode) where TMessage : class
        {
            switch (triggerParameterMode)
            {
            case TriggerParameterMode.Message:
                return(context.Message);

            case TriggerParameterMode.ConsumeContext:
                return(context);

            default:
                throw new ArgumentOutOfRangeException(nameof(triggerParameterMode), triggerParameterMode, null);
            }
        }
        public IMassTransitBusListener GetListener <TMessage>(string busName, string queueName, TriggerParameterMode triggerParameterMode, SessionUsage sessionUsage, ITriggeredFunctionExecutor contextExecutor)
            where TMessage : class
        {
            var configurationFactory = ServiceProvider.GetService <IServiceBusHostConfigurationFactory>();

            if (configurationFactory == null)
            {
                throw new InvalidOperationException("Unable to get the host configuration factory");
            }

            if (!Listeners.TryGetValue(busName, out var listener))
            {
                var hostConfiguration = configurationFactory.GetHostConfiguration(busName);
                if (hostConfiguration == null)
                {
                    throw new InvalidOperationException($"Unable to get the host configuration for {busName}");
                }
                listener = new Listener(hostConfiguration);
                Listeners.Add(busName, listener);
            }
            var triggerConfiguration = configurationFactory.GetTriggerConfiguration <TMessage>(busName)
                                       ?? new DefaultTriggerConfiguration <TMessage>();

            listener.RegisterQueueConfiguration(queueName, (cfg, host) =>
            {
                ConfigureSessionUsage(cfg, sessionUsage);
                cfg.Handler <TMessage>(
                    context => HandleMessageAsync(context, triggerParameterMode, contextExecutor),
                    triggerConfiguration.Configure);
            });
            return(listener);
        }