public void SetupSecondAzureServiceBusTestFixture() { _secondBus = CreateSecondBus(); _secondBusHandle = _secondBus.Start(); try { _secondBusSendEndpoint = Await(() => _secondBus.GetSendEndpoint(_secondBus.Address)); _secondInputQueueSendEndpoint = Await(() => _secondBus.GetSendEndpoint(_secondInputQueueAddress)); } catch (Exception) { try { using (var tokenSource = new CancellationTokenSource(TestTimeout)) { _secondBusHandle.Stop(tokenSource.Token); } } finally { _secondBusHandle = null; _secondBus = null; } throw; } }
public void Setup_quartz_service() { _scheduler.JobFactory = new MassTransitJobFactory(Bus); _scheduler.Start(); _quartzQueueSendEndpoint = GetSendEndpoint(_quartzQueueAddress).Result; }
public async Task Setup_quartz_service() { _scheduler.JobFactory = new MassTransitJobFactory(Bus); _scheduler.Start(); _quartzQueueSendEndpoint = await GetSendEndpoint(_quartzQueueAddress); }
public async Task Setup_quartz_service() { _quartzEndpoint = await GetSendEndpoint(QuartzAddress); SystemTime.UtcNow = GetUtcNow; SystemTime.Now = GetNow; }
public void SetupSecondAzureServiceBusTestFixture() { _secondBus = CreateSecondBus(); _secondBusHandle = _secondBus.Start(); try { _secondBusSendEndpoint = Await(() => _secondBus.GetSendEndpoint(_secondBus.Address)); _secondInputQueueSendEndpoint = Await(() => _secondBus.GetSendEndpoint(_secondInputQueueAddress)); } catch (Exception ex) { Console.WriteLine("The bus creation failed: {0}", ex); _secondBusHandle.Stop(); throw; } }
public async Task <TResponse> Request(TRequest request, CancellationToken cancellationToken) { var taskScheduler = SynchronizationContext.Current == null ? TaskScheduler.Default : TaskScheduler.FromCurrentSynchronizationContext(); Task <TResponse> responseTask = null; var pipe = new SendRequest <TRequest>(_bus, taskScheduler, x => { x.TimeToLive = _timeToLive; x.Timeout = _timeout; responseTask = x.Handle <TResponse>(); _callback?.Invoke(x); }); ISendEndpoint endpoint = await _requestEndpoint.Value.ConfigureAwait(false); await endpoint.Send(request, pipe, cancellationToken).ConfigureAwait(false); return(await responseTask.ConfigureAwait(false)); }
public virtual async Task Start(CancellationToken cancellationToken = default) { if (!cancellationToken.CanBeCanceled) { cancellationToken = TestCancellationToken; } _received = new BusTestReceiveObserver(TestInactivityTimeout); _received.ConnectInactivityObserver(InactivityObserver); _consumed = new BusTestConsumeObserver(TestTimeout, InactivityToken); _consumed.ConnectInactivityObserver(InactivityObserver); _published = new BusTestPublishObserver(TestTimeout, TestInactivityTimeout, InactivityToken); _published.ConnectInactivityObserver(InactivityObserver); _sent = new BusTestSendObserver(TestTimeout, TestInactivityTimeout, InactivityToken); _sent.ConnectInactivityObserver(InactivityObserver); PreCreateBus?.Invoke(this); BusControl = CreateBus(); ConnectObservers(BusControl); _busHandle = await BusControl.StartAsync(cancellationToken).ConfigureAwait(false); BusSendEndpoint = await GetSendEndpoint(BusControl.Address).ConfigureAwait(false); InputQueueSendEndpoint = await GetSendEndpoint(InputQueueAddress).ConfigureAwait(false); InputQueueSendEndpoint.ConnectSendObserver(_sent); BusControl.ConnectConsumeObserver(_consumed); BusControl.ConnectPublishObserver(_published); BusControl.ConnectReceiveObserver(_received); BusControl.ConnectSendObserver(_sent); }
public async Task RespondAsync <T>(T message, IPipe <SendContext> sendPipe) where T : class { if (message == null) { throw new ArgumentNullException(nameof(message)); } if (sendPipe == null) { throw new ArgumentNullException(nameof(sendPipe)); } if (ResponseAddress != null) { ISendEndpoint endpoint = await GetSendEndpoint(ResponseAddress).ConfigureAwait(false); await endpoint.Send(message, new ResponsePipe <T>(this, sendPipe), CancellationToken).ConfigureAwait(false); } else { await _publishEndpoint.Value.Publish(message, new ResponsePipe <T>(this, sendPipe), CancellationToken).ConfigureAwait(false); } }
/// <summary> /// Sends reply when message is received /// </summary> /// <param name="result">Result of registration</param> public static void SendReply(string result) { string address = "rabbitmq://localhost"; string queue = "uppgift4.domains.queueResult"; Uri rootUri = new Uri(address); IBusControl busControl = Bus.Factory.CreateUsingRabbitMq(r => { r.Host(rootUri, settings => { settings.Username("guest"); settings.Password("guest"); }); }); Task <ISendEndpoint> sendEndpointTask = busControl.GetSendEndpoint(new Uri(string.Concat(address, "/", queue))); ISendEndpoint sendEndpoint = sendEndpointTask.Result; Task sendTask = sendEndpoint.Send <IStudentRegistrationResult>(new { Reply = result }); }
public void SetupInMemoryTestFixture() { _bus = CreateBus(); _busHandle = _bus.Start(); try { Await(() => _busHandle.Ready); _busSendEndpoint = Await(() => _bus.GetSendEndpoint(_bus.Address)); _busSendEndpoint.ConnectSendObserver(_sendObserver); _inputQueueSendEndpoint = Await(() => _bus.GetSendEndpoint(_inputQueueAddress)); _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver); } catch (Exception) { _busHandle.Stop(new CancellationTokenSource(TestTimeout).Token); _busHandle = null; throw; } }
async Task DispatchAgent.Execute(DispatchContext context) { try { ISendEndpoint endpoint = await context.GetSendEndpoint(context.Destination); IPipe <SendContext> messageContext = CreateMessageContext(context); var dispatched = new Dispatched(); await endpoint.Send(dispatched, messageContext); PublishCommandForwardedEvent(context); } catch (Exception ex) { string message = string.Format(CultureInfo.InvariantCulture, "An exception occurred sending message {0} to {1}", string.Join(",", context.DispatchTypes), context.Destination); _log.Error(message, ex); throw new DispatchException(message, ex); } }
private static async Task SendOrders(ISendEndpoint endpointInstance) { Console.WriteLine("Press enter to send 1 message or a number + enter to send X messages."); Console.WriteLine("Type 'exit' to exit"); Console.WriteLine(); while (true) { var keys = Console.ReadLine(); int count; if (keys == "") { count = 1; } else if (string.Compare(keys, "exit", StringComparison.InvariantCultureIgnoreCase) == 0) { return; } else { if (!int.TryParse(keys, out count)) { await Console.Out.WriteLineAsync("Keys Not Recognized."); } } var sw = StopwatchExtensions.CreateStartSW(); for (var inc = 0; inc < count; inc++) { await SendOrder(endpointInstance, count > 1 && inc != count - 1); } if (count > 1) { await sw.LogTimeToConsoleAsync("GROUP COMPLETE "); } } }
public async Task SetupAzureServiceBusTestFixture() { _bus = CreateBus(); _bus.ConnectReceiveEndpointObserver(new ReceiveEndpointObserver()); _busHandle = await _bus.StartAsync(); try { _busSendEndpoint = await _bus.GetSendEndpoint(_bus.Address); _busSendEndpoint.ConnectSendObserver(_sendObserver); _inputQueueSendEndpoint = await _bus.GetSendEndpoint(_inputQueueAddress); _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver); } catch (Exception) { try { using (var tokenSource = new CancellationTokenSource(TestTimeout)) { await _bus.StopAsync(tokenSource.Token); } } finally { _busHandle = null; _bus = null; } throw; } }
public BusTestScenario(TimeSpan timeout, IBusControl busControl) { _timeout = timeout; _busControl = busControl; Received = new ReceivedMessageList(timeout); _skipped = new ReceivedMessageList(timeout); _published = new PublishedMessageList(timeout); _tokenSource = new CancellationTokenSource(timeout); CancellationToken = _tokenSource.Token; _subjectSendEndpoint = _busControl.GetSendEndpoint(new Uri("loopback://localhost/input_queue")).Result; var testSendObserver = new TestSendObserver(timeout); Sent = testSendObserver.Messages; _subjectSendEndpoint.ConnectSendObserver(testSendObserver); var consumeObserver = new TestConsumeObserver(timeout); Received = consumeObserver.Messages; busControl.ConnectConsumeObserver(consumeObserver); _busHandle = _busControl.Start(); }
public void Execute(IJobExecutionContext context) { try { var destinationAddress = new Uri(Destination); Uri sourceAddress = _bus.Address; IPipe <SendContext> sendPipe = CreateMessageContext(sourceAddress, destinationAddress, context.Trigger.Key.Name); ISendEndpoint endpoint = TaskUtil.Await(() => _bus.GetSendEndpoint(destinationAddress)); var scheduled = new Scheduled(); TaskUtil.Await(() => endpoint.Send(scheduled, sendPipe)); } catch (Exception ex) { string message = string.Format(CultureInfo.InvariantCulture, "An exception occurred sending message {0} to {1}", MessageType, Destination); _log.Error(message, ex); throw new JobExecutionException(message, ex); } }
public async Task Evaluate() { RoutingSlipBuilder builder = CreateRoutingSlipBuilder(_routingSlip); Build(builder); RoutingSlip routingSlip = builder.Build(); await PublishActivityEvents(routingSlip, builder).ConfigureAwait(false); if (HasNextActivity(routingSlip)) { ISendEndpoint endpoint = await _context.GetSendEndpoint(routingSlip.GetNextExecuteAddress()).ConfigureAwait(false); await _context.Forward(endpoint, routingSlip).ConfigureAwait(false); } else { DateTime completedTimestamp = _context.Timestamp + _duration; TimeSpan completedDuration = completedTimestamp - _routingSlip.CreateTimestamp; await _publisher.PublishRoutingSlipCompleted(completedTimestamp, completedDuration, routingSlip.Variables).ConfigureAwait(false); } }
public ScopedSendEndpoint(ISendEndpoint endpoint, TScope scope) { _endpoint = endpoint; _scope = scope; }
public CachedSendEndpoint(TKey key, ISendEndpoint endpoint) { Key = key; _endpoint = endpoint; }
public TransactionOutboxSendEndpoint(TransactionOutbox transactionOutbox, ISendEndpoint sendEndpoint) { _transactionOutbox = transactionOutbox; _sendEndpoint = sendEndpoint; }
public ReplyToSendEndpoint(ISendEndpoint endpoint, string queueName) : base(endpoint) { _queueName = queueName; }
/// <summary> /// Send a message /// </summary> /// <typeparam name="T">The message type</typeparam> /// <param name="bus">The consume context</param> /// <param name="schedulerEndpoint">The scheduler endpoint</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="message">The message</param> /// <param name="pipe"></param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage <T> > SchedulePublish <T>(this IBus bus, ISendEndpoint schedulerEndpoint, DateTime scheduledTime, T message, IPipe <SendContext> pipe, CancellationToken cancellationToken = default(CancellationToken)) where T : class { var destinationAddress = GetPublishAddress <T>(bus); return(schedulerEndpoint.ScheduleSend(destinationAddress, scheduledTime, message, pipe, cancellationToken)); }
/// <summary> /// Send a message /// </summary> /// <typeparam name="T">The message type</typeparam> /// <param name="bus">The consume context</param> /// <param name="schedulerEndpoint">The scheduler endpoint</param> /// <param name="delay">The time at which the message should be delivered to the queue</param> /// <param name="message">The message</param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage <T> > SchedulePublish <T>(this IBus bus, ISendEndpoint schedulerEndpoint, TimeSpan delay, T message, CancellationToken cancellationToken = default(CancellationToken)) where T : class { var scheduledTime = DateTime.UtcNow + delay; return(SchedulePublish(bus, schedulerEndpoint, scheduledTime, message, cancellationToken)); }
public CreateNewsCommandHandler(IBus bus, IConfiguration configuration) { _bus = bus ?? throw new ArgumentNullException(nameof(bus)); _configuration = configuration ?? throw new ArgumentNullException(nameof(configuration)); _sendEndpoint = _bus.GetSendEndpoint(new Uri($"{_configuration.GetSection("RabbitMqSettings:server").Value}/News")).GetAwaiter().GetResult(); }
public static Task Send(ISendEndpoint endpoint, object message, Type messageType, IPipe<SendContext> pipe, CancellationToken cancellationToken = default(CancellationToken)) { return Cached.Converters.Value[messageType].Send(endpoint, message, pipe, cancellationToken); }
public UserService(IBusControl busControl) { _endpoint = busControl.GetSendEndpoint(new Uri($"{RabbitMQConstants.RabbitMQUri}{RabbitMQConstants.UserManagementWriteQueue}")).Result; }
async Task RunStripe(ISendEndpoint targetEndpoint, long messageCount) { await Task.Yield(); for (long i = 0; i < messageCount; i++) { Guid messageId = NewId.NextGuid(); Task task = targetEndpoint.Send(new LatencyTestMessage(messageId, _payload)); await _capture.Sent(messageId, task); } }
public async Task CancelScheduledSend(Guid tokenId) { ISendEndpoint endpoint = await _schedulerEndpoint.Value.ConfigureAwait(false); await endpoint.CancelScheduledSend(tokenId).ConfigureAwait(false); }
protected SendEndpointProxy(ISendEndpoint endpoint) { _endpoint = endpoint; }
public async Task Setup_quartz_service() { _quartzEndpoint = await GetSendEndpoint(QuartzAddress); }
protected async Task <ISendEndpoint> GetSendEndpoint(Uri address) { ISendEndpoint sendEndpoint = await _bus.GetSendEndpoint(address).ConfigureAwait(false); return(sendEndpoint); }
public ValuesController(ISendEndpoint endPoint) { _endPoint = endPoint; }
/// <summary> /// Sends an interface message, initializing the properties of the interface using the anonymous /// object specified /// </summary> /// <typeparam name="T">The interface type to send</typeparam> /// <param name="bus">The consume context</param> /// <param name="schedulerEndpoint">The scheduler endpoint</param> /// <param name="scheduledTime">The time at which the message should be delivered to the queue</param> /// <param name="values">The property values to initialize on the interface</param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage <T> > SchedulePublish <T>(this IBus bus, ISendEndpoint schedulerEndpoint, DateTime scheduledTime, object values, CancellationToken cancellationToken = default(CancellationToken)) where T : class { var destinationAddress = GetPublishAddress <T>(bus); return(schedulerEndpoint.ScheduleSend <T>(destinationAddress, scheduledTime, values, cancellationToken)); }
public void SetupAzureServiceBusTestFixture() { _bus = CreateBus(); _bus.ConnectReceiveEndpointObserver(new ReceiveEndpointObserver()); _busHandle = _bus.Start(); try { Await(() => _busHandle.Ready); _busSendEndpoint = _bus.GetSendEndpoint(_bus.Address).Result; _busSendEndpoint.ConnectSendObserver(_sendObserver); _inputQueueSendEndpoint = _bus.GetSendEndpoint(_inputQueueAddress).Result; _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver); } catch (Exception ex) { Console.WriteLine("The bus creation failed: {0}", ex); _busHandle.Stop(); throw; } }
/// <summary> /// Sends an interface message, initializing the properties of the interface using the anonymous /// object specified /// </summary> /// <typeparam name="T">The interface type to send</typeparam> /// <param name="bus">The consume context</param> /// <param name="values">The property values to initialize on the interface</param> /// <param name="schedulerEndpoint"></param> /// <param name="delay">The time at which the message should be delivered to the queue</param> /// <param name="pipe"></param> /// <param name="cancellationToken"></param> /// <returns>The task which is completed once the Send is acknowledged by the broker</returns> public static Task <ScheduledMessage <T> > SchedulePublish <T>(this IBus bus, ISendEndpoint schedulerEndpoint, TimeSpan delay, object values, IPipe <SendContext> pipe, CancellationToken cancellationToken = default(CancellationToken)) where T : class { var scheduledTime = DateTime.UtcNow + delay; return(SchedulePublish <T>(bus, schedulerEndpoint, scheduledTime, values, pipe, cancellationToken)); }
/// <summary> /// Forward the message to another consumer /// </summary> /// <param name="context"></param> /// <param name="endpoint">The endpoint to forward the message tosaq</param> /// <param name="message"></param> public static Task Forward <T>(this ConsumeContext context, ISendEndpoint endpoint, T message) where T : class { return(endpoint.Send(message, CreateCopyContextPipe(context, GetForwardHeaders))); }
public static Task Send(ISendEndpoint endpoint, object message, Type messageType, IPipe <SendContext> pipe, CancellationToken cancellationToken = default(CancellationToken)) { return(Cached.Converters.Value[messageType].Send(endpoint, message, pipe, cancellationToken)); }
public CommandBasedAccountSequenceNotifier(ISendEndpoint workerEndpoint) { _workerEndpoint = workerEndpoint; }
public async Task Setup_quartz_service() { _quartzQueueSendEndpoint = await GetSendEndpoint(_quartzQueueAddress); }
public ReplyToSendEndpoint(ISendEndpoint endpoint, string queueName) { _endpoint = endpoint; _queueName = queueName; }
public void Setup_quartz_service() { _quartzEndpoint = Await(() => GetSendEndpoint(QuartzAddress)); }
public ConsumeSendEndpoint(ISendEndpoint endpoint, ConsumeContext context) { _endpoint = endpoint; _context = context; }
public void SetupInMemoryTestFixture() { _bus = CreateBus(); _busHandle = _bus.Start(); try { _busSendEndpoint = Await(() => _bus.GetSendEndpoint(_bus.Address)); _busSendEndpoint.ConnectSendObserver(_sendObserver); _inputQueueSendEndpoint = Await(() => _bus.GetSendEndpoint(_inputQueueAddress)); _inputQueueSendEndpoint.ConnectSendObserver(_sendObserver); } catch (Exception) { try { using (var tokenSource = new CancellationTokenSource(TestTimeout)) { _busHandle?.Stop(tokenSource.Token); } } finally { _busHandle = null; _bus = null; } throw; } }