public ServiceBusTriggerAttributeBindingProvider(INameResolver nameResolver, ServiceBusOptions options, MessagingProvider messagingProvider, IConfiguration configuration) { _nameResolver = nameResolver ?? throw new ArgumentNullException(nameof(nameResolver)); _options = options ?? throw new ArgumentNullException(nameof(options)); _messagingProvider = messagingProvider ?? throw new ArgumentNullException(nameof(messagingProvider)); _configuration = configuration; }
public ServiceBusListener( string functionId, EntityType entityType, string entityPath, bool isSessionsEnabled, ITriggeredFunctionExecutor triggerExecutor, ServiceBusOptions options, string connection, MessagingProvider messagingProvider, ILoggerFactory loggerFactory, bool singleDispatch, ServiceBusClientFactory clientFactory) { _functionId = functionId; _entityType = entityType; _entityPath = entityPath; _isSessionsEnabled = isSessionsEnabled; _triggerExecutor = triggerExecutor; _cancellationTokenSource = new CancellationTokenSource(); _messagingProvider = messagingProvider; _loggerFactory = loggerFactory; _logger = loggerFactory.CreateLogger <ServiceBusListener>(); _client = new Lazy <ServiceBusClient>(() => clientFactory.CreateClientFromSetting(connection)); _batchReceiver = new Lazy <ServiceBusReceiver>(() => _messagingProvider.CreateBatchMessageReceiver(_client.Value, _entityPath)); _messageProcessor = new Lazy <MessageProcessor>(() => _messagingProvider.CreateMessageProcessor(_client.Value, _entityPath)); _sessionMessageProcessor = new Lazy <SessionMessageProcessor>(() => _messagingProvider.CreateSessionMessageProcessor(_client.Value, _entityPath)); _scaleMonitor = new Lazy <ServiceBusScaleMonitor>(() => new ServiceBusScaleMonitor(_functionId, _entityType, _entityPath, connection, _batchReceiver, _loggerFactory, clientFactory)); _singleDispatch = singleDispatch; _serviceBusOptions = options; }
public void DeepClone() { var options = new ServiceBusOptions(); var clonedOptions = ServiceBusOptions.DeepClone(options); Assert.NotEqual(options, clonedOptions); Assert.Equal(options.PrefetchCount, clonedOptions.PrefetchCount); Assert.Equal(options.ExceptionHandler, clonedOptions.ExceptionHandler); Assert.Equal(options.MessageHandlerOptions.AutoComplete, clonedOptions.MessageHandlerOptions.AutoComplete); Assert.Equal(options.MessageHandlerOptions.MaxAutoRenewDuration.Ticks, clonedOptions.MessageHandlerOptions.MaxAutoRenewDuration.Ticks); Assert.Equal(options.MessageHandlerOptions.MaxConcurrentCalls, clonedOptions.MessageHandlerOptions.MaxConcurrentCalls); Assert.Equal(options.BatchOptions.AutoComplete, clonedOptions.BatchOptions.AutoComplete); Assert.Equal(options.BatchOptions.MaxMessageCount, clonedOptions.BatchOptions.MaxMessageCount); Assert.Equal(options.BatchOptions.OperationTimeout.Ticks, clonedOptions.BatchOptions.OperationTimeout.Ticks); Assert.Equal(options.SessionHandlerOptions.AutoComplete, clonedOptions.SessionHandlerOptions.AutoComplete); Assert.Equal(options.SessionHandlerOptions.MaxAutoRenewDuration.Ticks, clonedOptions.SessionHandlerOptions.MaxAutoRenewDuration.Ticks); Assert.Equal(options.SessionHandlerOptions.MaxConcurrentSessions, clonedOptions.SessionHandlerOptions.MaxConcurrentSessions); Assert.Equal(options.SessionHandlerOptions.MessageWaitTimeout.Ticks, clonedOptions.SessionHandlerOptions.MessageWaitTimeout.Ticks); // Perform updates on cloned options. They should not copied over to the source clonedOptions.MessageHandlerOptions.AutoComplete = options.BatchOptions.AutoComplete = options.SessionHandlerOptions.AutoComplete = false; Assert.NotEqual(options.MessageHandlerOptions.AutoComplete, clonedOptions.MessageHandlerOptions.AutoComplete); Assert.NotEqual(options.BatchOptions.AutoComplete, clonedOptions.BatchOptions.AutoComplete); Assert.NotEqual(options.SessionHandlerOptions.AutoComplete, clonedOptions.SessionHandlerOptions.AutoComplete); clonedOptions.MessageHandlerOptions.MaxAutoRenewDuration = new TimeSpan(0, 10, 0); Assert.NotEqual(options.MessageHandlerOptions.MaxAutoRenewDuration.Ticks, clonedOptions.MessageHandlerOptions.MaxAutoRenewDuration.Ticks); }
public void Constructor_SetsExpectedDefaults() { ServiceBusOptions config = new ServiceBusOptions(); Assert.AreEqual(16 * Utility.GetProcessorCount(), config.MessageHandlerOptions.MaxConcurrentCalls); Assert.AreEqual(0, config.PrefetchCount); }
public void Setup() { _mockExecutor = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict); var client = new ServiceBusClient(_testConnection); ServiceBusProcessorOptions processorOptions = new ServiceBusProcessorOptions(); ServiceBusProcessor messageProcessor = client.CreateProcessor(_entityPath); _mockMessageProcessor = new Mock <MessageProcessor>(MockBehavior.Strict, messageProcessor); _serviceBusOptions = new ServiceBusOptions(); _mockMessagingProvider = new Mock <MessagingProvider>(MockBehavior.Strict, new OptionsWrapper <ServiceBusOptions>(_serviceBusOptions)); _mockMessagingProvider .Setup(p => p.CreateMessageProcessor(_entityPath, _testConnection)) .Returns(_mockMessageProcessor.Object); _mockServiceBusAccount = new Mock <ServiceBusAccount>(MockBehavior.Strict); _mockServiceBusAccount.Setup(a => a.ConnectionString).Returns(_testConnection); _loggerFactory = new LoggerFactory(); _loggerProvider = new TestLoggerProvider(); _loggerFactory.AddProvider(_loggerProvider); _listener = new ServiceBusListener(_functionId, EntityType.Queue, _entityPath, false, _mockExecutor.Object, _serviceBusOptions, _mockServiceBusAccount.Object, _mockMessagingProvider.Object, _loggerFactory, false); _scaleMonitor = (ServiceBusScaleMonitor)_listener.GetMonitor(); }
public async Task DispatchAsync(ExecuteWorkflowInstanceRequest request, CancellationToken cancellationToken = default) { var workflowInstance = await _workflowInstanceStore.FindByIdAsync(request.WorkflowInstanceId, cancellationToken); if (workflowInstance == null) { _logger.LogWarning("Cannot dispatch a workflow instance ID that does not exist"); return; } var workflowBlueprint = await _workflowRegistry.FindAsync(workflowInstance.DefinitionId, VersionOptions.SpecificVersion(workflowInstance.Version), workflowInstance.TenantId, cancellationToken); if (workflowBlueprint == null) { _logger.LogWarning("Workflow instance {WorkflowInstanceId} references workflow blueprint {WorkflowDefinitionId} with version {Version}, but could not be found", workflowInstance.Id, workflowInstance.DefinitionId, workflowInstance.Version); return; } var channel = _workflowChannelOptions.GetChannelOrDefault(workflowBlueprint.Channel); var queue = ServiceBusOptions.FormatChannelQueueName <ExecuteWorkflowInstanceRequest>(channel); EnqueueJob <WorkflowInstanceJob>(x => x.ExecuteAsync(request, CancellationToken.None), queue); }
public void ConfigureServices(IServiceCollection services) { services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1); services.AddMongoDB(Configuration.GetConnectionString("MongoDB")); services.AddMufloneEventStore(Configuration.GetConnectionString("EventStore")); services.Configure <ServiceBusOptions>(Configuration.GetSection("MassTransit:RabbitMQ")); var serviceBusOptions = new ServiceBusOptions(); Configuration.GetSection("MassTransit:RabbitMQ").Bind(serviceBusOptions); services.AddMufloneMassTransitWithRabbitMQ(serviceBusOptions, x => { x.AddConsumer <CreateDailyProgrammingConsumer>(); x.AddConsumer <DailyProgrammingCreatedConsumer>(); }); services.AddSwaggerGen(c => { c.SwaggerDoc("v1", new Info { Title = "IAD 2018", Version = "v1", Description = "Web Api Services for CQRS-ES workshop", TermsOfService = "" }); var pathDoc = "CqrsMovie.Seats.API.xml"; var filePath = Path.Combine(PlatformServices.Default.Application.ApplicationBasePath, pathDoc); if (File.Exists(filePath)) { c.IncludeXmlComments(filePath); } c.DescribeAllEnumsAsStrings(); }); }
public async Task DispatchAsync(ExecuteWorkflowInstanceRequest request, CancellationToken cancellationToken = default) { using var loggingScope = _logger.BeginScope(new Dictionary <string, object> { ["WorkflowInstanceId"] = request.WorkflowInstanceId }); var workflowInstance = await _workflowInstanceStore.FindByIdAsync(request.WorkflowInstanceId, cancellationToken); if (workflowInstance == null) { _logger.LogWarning("Cannot dispatch a workflow instance ID that does not exist"); return; } var workflowBlueprint = await _workflowRegistry.FindAsync(workflowInstance.DefinitionId, VersionOptions.SpecificVersion(workflowInstance.Version), workflowInstance.TenantId, cancellationToken); if (workflowBlueprint == null) { _logger.LogWarning("Workflow instance {WorkflowInstanceId} references workflow blueprint {WorkflowDefinitionId} with version {Version}, but could not be found", workflowInstance.Id, workflowInstance.DefinitionId, workflowInstance.Version); return; } var channel = _workflowChannelOptions.GetChannelOrDefault(workflowBlueprint.Channel); var queue = ServiceBusOptions.FormatChannelQueueName <ExecuteWorkflowInstanceRequest>(channel); _logger.LogDebug("Dispatching workflow instance to queue {Queue}", queue); await _commandSender.SendAsync(request, queue, cancellationToken : cancellationToken); }
public ServiceBusListenerTests() { _mockExecutor = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict); MessageHandlerOptions messageOptions = new MessageHandlerOptions(ExceptionReceivedHandler); MessageReceiver messageReceiver = new MessageReceiver(_testConnection, _entityPath); _mockMessageProcessor = new Mock <MessageProcessor>(MockBehavior.Strict, messageReceiver, messageOptions); ServiceBusOptions config = new ServiceBusOptions { MessageHandlerOptions = messageOptions }; _mockMessagingProvider = new Mock <MessagingProvider>(MockBehavior.Strict, new OptionsWrapper <ServiceBusOptions>(config)); _mockMessagingProvider.Setup(p => p.CreateMessageProcessor(_entityPath, _testConnection)) .Returns(_mockMessageProcessor.Object); ServiceBusTriggerExecutor triggerExecutor = new ServiceBusTriggerExecutor(_mockExecutor.Object); var mockServiceBusAccount = new Mock <ServiceBusAccount>(MockBehavior.Strict); mockServiceBusAccount.Setup(a => a.ConnectionString).Returns(_testConnection); _listener = new ServiceBusListener(_entityPath, false, triggerExecutor, config, mockServiceBusAccount.Object, _mockMessagingProvider.Object); }
public ServiceBusTriggerBinding(string parameterName, Type parameterType, ITriggerDataArgumentBinding <Message> argumentBinding, ServiceBusAccount account, ServiceBusOptions options, MessagingProvider messagingProvider, string queueName) : this(parameterName, parameterType, argumentBinding, account, options, messagingProvider) { _queueName = queueName; _entityPath = queueName; }
public void AddPolicyForTest() { var options = new ServiceBusOptions(); options.AddPolicyFor <IMessage>("CustomPolicy"); Assert.Equal("CustomPolicy", options.GetPolicyFor(typeof(IMessage))); }
public ServiceBusListener(string functionId, EntityType entityType, string entityPath, bool isSessionsEnabled, ITriggeredFunctionExecutor triggerExecutor, ServiceBusOptions config, ServiceBusAccount serviceBusAccount, MessagingProvider messagingProvider, ILoggerFactory loggerFactory, bool singleDispatch) { _functionId = functionId; _entityType = entityType; _entityPath = entityPath; _isSessionsEnabled = isSessionsEnabled; _triggerExecutor = triggerExecutor; _cancellationTokenSource = new CancellationTokenSource(); _messagingProvider = messagingProvider; _serviceBusAccount = serviceBusAccount; _loggerFactory = loggerFactory; _logger = loggerFactory.CreateLogger <ServiceBusListener>(); _receiver = CreateMessageReceiver(); _sessionClient = CreateSessionClient(); _scaleMonitor = new Lazy <ServiceBusScaleMonitor>(() => new ServiceBusScaleMonitor(_functionId, _entityType, _entityPath, _serviceBusAccount.ConnectionString, _receiver, _loggerFactory)); _singleDispatch = singleDispatch; if (_isSessionsEnabled) { _sessionMessageProcessor = _messagingProvider.CreateSessionMessageProcessor(_entityPath, _serviceBusAccount.ConnectionString); } else { _messageProcessor = _messagingProvider.CreateMessageProcessor(entityPath, _serviceBusAccount.ConnectionString); } _serviceBusOptions = config; }
public IBus ConfigureServiceBus(IEnumerable <Type> messageTypes, string queueName) { queueName = ServiceBusOptions.FormatQueueName(queueName); var prefixedQueueName = PrefixQueueName(queueName); var messageTypeList = messageTypes.ToList(); var configurer = Configure.With(_handlerActivator); var map = messageTypeList.ToDictionary(x => x, _ => prefixedQueueName); var configureContext = new ServiceBusEndpointConfigurationContext(configurer, prefixedQueueName, map, _serviceProvider); // Default options. configurer .Serialization(serializer => serializer.UseNewtonsoftJson(DefaultContentSerializer.CreateDefaultJsonSerializationSettings())) .Logging(l => l.MicrosoftExtensionsLogging(_loggerFactory)) .Routing(r => r.TypeBased().Map(map)) .Options(options => options.Apply(_elsaOptions.ServiceBusOptions)); // Configure transport. _elsaOptions.ConfigureServiceBusEndpoint(configureContext); var newBus = configurer.Start(); _serviceBuses.Add(prefixedQueueName, newBus); foreach (var messageType in messageTypeList) { _messageTypeQueueDictionary[messageType] = prefixedQueueName; } return(newBus); }
public ServiceBusScaleMonitorTests() { _mockExecutor = new Mock <ITriggeredFunctionExecutor>(MockBehavior.Strict); MessageHandlerOptions messageOptions = new MessageHandlerOptions(ExceptionReceivedHandler); MessageReceiver messageReceiver = new MessageReceiver(_testConnection, _entityPath); _mockMessageProcessor = new Mock <MessageProcessor>(MockBehavior.Strict, messageReceiver, messageOptions); _serviceBusOptions = new ServiceBusOptions { MessageHandlerOptions = messageOptions }; _mockMessagingProvider = new Mock <MessagingProvider>(MockBehavior.Strict, new OptionsWrapper <ServiceBusOptions>(_serviceBusOptions)); _mockMessagingProvider .Setup(p => p.CreateMessageProcessor(_entityPath, _testConnection)) .Returns(_mockMessageProcessor.Object); _triggerExecutor = new ServiceBusTriggerExecutor(_mockExecutor.Object); _mockServiceBusAccount = new Mock <ServiceBusAccount>(MockBehavior.Strict); _mockServiceBusAccount.Setup(a => a.ConnectionString).Returns(_testConnection); _loggerFactory = new LoggerFactory(); _loggerProvider = new TestLoggerProvider(); _loggerFactory.AddProvider(_loggerProvider); _listener = new ServiceBusListener(_functionId, EntityType.Queue, _entityPath, false, _triggerExecutor, _serviceBusOptions, _mockServiceBusAccount.Object, _mockMessagingProvider.Object, _loggerFactory); _scaleMonitor = (ServiceBusScaleMonitor)_listener.GetMonitor(); }
public ValidationServiceStateless(StatelessServiceContext context, ILifetimeScope parentLifeTimeScope, ILogger logger, ITopicHelper topicHelper, ServiceBusOptions seviceBusOptions, Func <IValidationService> validationServiceFactory, IActorsHelper actorsHelper) : base(context) { _parentLifeTimeScope = parentLifeTimeScope; //get config values _queueName = seviceBusOptions.QueueName; _serviceBusConnectionString = seviceBusOptions.ServiceBusConnectionString; _fundingCalcSqlFilterValue = seviceBusOptions.FundingCalcSqlFilterValue; _actorsHelper = actorsHelper; //using serviceremoting v2 _valResultsServiceProxyFactory = new ServiceProxyFactory( (c) => new FabricTransportServiceRemotingClientFactory( remotingSettings: FabricTransportRemotingSettings.LoadFrom("DataTransportSettings"), remotingCallbackMessageHandler: null, servicePartitionResolver: null, exceptionHandlers: null, traceId: null, serializationProvider: new ServiceRemotingJsonSerializationProvider())); // _logger = logger; _topicHelper = topicHelper; _validationServiceFactory = validationServiceFactory; }
public static IServiceCollection AddServiceBus(this IServiceCollection services, Action <ServiceBusOptions> setupAction) { ServiceBusOptions options = new ServiceBusOptions(); setupAction.Invoke(options); services.AddMassTransit(cfg => { cfg.AddConsumer <Community.Domain.IntegrationEventHandlers.Identity.IdentityIntegrationEventHandler>(); }); services.AddSingleton(provider => Bus.Factory.CreateUsingRabbitMq(transport => { Uri hostAddress = new Uri(options.HostAddress); IRabbitMqHost host = transport.Host(hostAddress, cfg => { cfg.Username(options.RabbitMqHostUser); cfg.Password(options.RabbitMqHostPassword); }); transport.ReceiveEndpoint(host, options.RabbitMqQueueName, endpoint => { endpoint.UseRetry(r => r.Immediate(3)); endpoint.Consumer <Community.Domain.IntegrationEventHandlers.Identity.IdentityIntegrationEventHandler>(provider); }); })); services.AddSingleton <IIntegrationServiceBus, IntegrationServiceBus>(); services.AddHostedService <MassTransitProcess>(); return(services); }
public ServiceBusQueueListenerFactory(ServiceBusAccount account, string queueName, ITriggeredFunctionExecutor executor, ServiceBusOptions options, MessagingProvider messagingProvider) { _account = account; _queueName = queueName; _executor = executor; _options = options; _messagingProvider = messagingProvider; }
private void BuildAndRegisterSubscription(SubscriptionOptions options, ServiceBusOptions parentOptions) { var subscription = new SubscriptionWrapper(options, parentOptions, _provider); subscription.Initialize(); _registry.Register(subscription); }
private void BuildAndRegisterTopic(TopicOptions options, ServiceBusOptions parentOptions) { var topic = new TopicWrapper(options, parentOptions, _provider); topic.Initialize(); _registry.Register(topic); }
private void BuildAndRegisterQueue(QueueOptions options, ServiceBusOptions parentOptions) { var queue = new QueueWrapper(options, parentOptions, _provider); queue.Initialize(); _registry.Register(queue); }
public TopicWrapper( TopicOptions options, ServiceBusOptions parentOptions, IServiceProvider provider) : base(parentOptions, provider, options.TopicName) { _options = options; }
public CustomMessagingProvider( IOptions <ServiceBusOptions> serviceBusOptions, ILoggerFactory loggerFactory) : base(serviceBusOptions) { _options = serviceBusOptions.Value; _logger = loggerFactory?.CreateLogger(CustomMessagingCategory); }
public CustomMessagingProvider(IOptions <ServiceBusOptions> serviceBusOptions, ILoggerFactory loggerFactory) : base(serviceBusOptions) { _options = serviceBusOptions.Value; _options.SessionHandlerOptions.MessageWaitTimeout = TimeSpan.FromSeconds(90); _options.SessionHandlerOptions.MaxConcurrentSessions = 1; _logger = loggerFactory?.CreateLogger(CustomMessagingCategory); }
public void PrefetchCount_GetSet() { ServiceBusOptions config = new ServiceBusOptions(); Assert.AreEqual(0, config.PrefetchCount); config.PrefetchCount = 100; Assert.AreEqual(100, config.PrefetchCount); }
public ServiceBusTriggerBinding(string parameterName, Type parameterType, ITriggerDataArgumentBinding <Message> argumentBinding, ServiceBusAccount account, ServiceBusOptions options, MessagingProvider messagingProvider, string topicName, string subscriptionName) : this(parameterName, parameterType, argumentBinding, account, options, messagingProvider) { _topicName = topicName; _subscriptionName = subscriptionName; _entityPath = EntityNameHelper.FormatSubscriptionPath(topicName, subscriptionName); }
public QueueWrapper(QueueOptions options, ServiceBusOptions parentOptions, IServiceProvider provider) : base( options, parentOptions, provider, options.QueueName) { _options = options; }
public void ConfigureOptions_AppliesValuesCorrectly_BackCompat() { ServiceBusOptions options = CreateOptionsFromConfigBackCompat(); Assert.AreEqual(123, options.PrefetchCount); Assert.AreEqual(123, options.MaxConcurrentCalls); Assert.False(options.AutoCompleteMessages); Assert.AreEqual(TimeSpan.FromSeconds(15), options.MaxAutoLockRenewalDuration); }
public ServiceBusAdapterReceiver(SerializationManager serializationManager, ILoggerFactory loggerFactory, ServiceBusClient serviceBusClient, ServiceBusOptions queueOptions, string queueName) { _logger = loggerFactory.CreateLogger <ServiceBusAdapterReceiver>(); _serializationManager = serializationManager; _queueOptions = queueOptions; _queueName = queueName; _client = serviceBusClient; }
public ServiceBusListenerFactory(ServiceBusAccount account, string entityPath, bool isSessionsEnabled, ITriggeredFunctionExecutor executor, ServiceBusOptions options, MessagingProvider messagingProvider) { _account = account; _entityPath = entityPath; _isSessionsEnabled = isSessionsEnabled; _executor = executor; _options = options; _messagingProvider = messagingProvider; }
public ServiceBusController(IOptions <ServiceBusOptions> serviceBusOptions) { if (serviceBusOptions == null) { throw new ArgumentNullException(nameof(serviceBusOptions)); } this.serviceBusOptions = serviceBusOptions.Value; }