public void TryReceivePostAndReply_with_TryScan_timeout(int timeout) { // Given var mb = MailboxProcessor.Start <IReplyChannel <int?> >(async inbox => { var replyChannel = await inbox.TryReceive(); if (replyChannel == null) { Assert.True(false); return; } var scanRes = await inbox.TryScan(__ => { Assert.True(false, "Should have timedout"); return(Task.FromResult(inbox)); }, timeout); if (scanRes == null) { replyChannel.Reply(200); } else { Assert.True(false, "TryScan should have failed"); } }); // When var result1 = mb.PostAndReply <int?>(channel => channel); // Then Assert.Equal(200, result1); }
public EventSubscriber(IMessageQueueClient messageQueueClient, IHandlerProvider handlerProvider, ICommandBus commandBus, IMessagePublisher messagePublisher, string subscriptionName, TopicSubscription[] topicSubscriptions, string consumerId, ConsumerConfig consumerConfig = null) { ConsumerConfig = consumerConfig ?? ConsumerConfig.DefaultConfig; MessageQueueClient = messageQueueClient; HandlerProvider = handlerProvider; _topicSubscriptions = topicSubscriptions ?? new TopicSubscription[0]; _topicSubscriptions.Where(ts => ts.TagFilter != null) .ForEach(ts => { TagFilters.Add(ts.Topic, ts.TagFilter); }); ConsumerId = consumerId; SubscriptionName = subscriptionName; MessagePublisher = messagePublisher; CommandBus = commandBus; var loggerFactory = ObjectProviderFactory.GetService <ILoggerFactory>(); MessageProcessor = new MailboxProcessor(new DefaultProcessingMessageScheduler(), new OptionsWrapper <MailboxOption>(new MailboxOption { BatchCount = ConsumerConfig.MailboxProcessBatchCount }), loggerFactory.CreateLogger <MailboxProcessor>()); Logger = loggerFactory.CreateLogger(GetType().Name); }
public void PostReceive(int n) { // Given var received = 0L; var mb = MailboxProcessor.Start <Option <int> >(async inbox => { for (var i = 0; i < n; i++) { var _ = await inbox.Receive(); Interlocked.Increment(ref received); } }); // When for (var i = 0; i < n; i++) { mb.Post(Some(i)); } // Then while (received < n) { var numReceived = Interlocked.Read(ref received); if (numReceived % 100 == 0) { Trace.WriteLine(string.Format("received = {0}", numReceived)); } Thread.Sleep(1); } Assert.Equal(n, received); }
public void TryReceivePostAndReply_with_Scan_timeout(int timeout) { // Given var mb = MailboxProcessor.Start <IReplyChannel <int?> >(async inbox => { var replyChannel = await inbox.TryReceive(); if (replyChannel == null) { Assert.True(false); return; } try { var _ = await inbox.Scan(__ => { Assert.True(false, "Should have timedout"); return(Task.FromResult(inbox)); }, timeout); Assert.True(false, "should have received timeout"); } catch (TimeoutException) { replyChannel.Reply(200); } }); // When var result1 = mb.PostAndReply <int?>(channel => channel); // Then Assert.Equal(200, result1); }
public void TryReceive_PostAndReply() { // Given var mb = MailboxProcessor.Start <IReplyChannel <int?> >(async inbox => { var msg = await inbox.TryReceive(); if (msg == null) { Assert.True(false); return; } msg.Reply(100); var msg2 = await inbox.TryReceive(); if (msg2 == null) { Assert.True(false); return; } msg2.Reply(200); }); // When var result1 = mb.PostAndReply <int?>(channel => channel); var result2 = mb.PostAndReply <int?>(channel => channel); // Then Assert.Equal(100, result1); Assert.Equal(200, result2); }
public void MailboxProcessor_null() { // Given var mb = new MailboxProcessor<IReplyChannel<int?>>(async inbox => { }); // When mb.Start(); // Then // no exceptions }
public void MailboxProcessor_null() { // Given var mb = new MailboxProcessor <IReplyChannel <int?> >(async inbox => { }); // When mb.Start(); // Then // no exceptions }
internal RealTimeAgent_Mailbox(Agent agent) : base(agent) { mailbox = MailboxProcessor.Start <Message>(async mb => { while (true) { var message = await mb.Receive(); agent.HandleMessage(message); } }); }
public void Receive_PostAndReply() { // Given var mb = MailboxProcessor.Start <IReplyChannel <int?> >(async inbox => { var msg = await inbox.Receive(); msg.Reply(100); }); // When var result = mb.PostAndReply <int?>(channel => channel); Assert.Equal(100, result); }
public void PostTryReceive(int timeout, int n) { // Given var received = 0L; var mb = MailboxProcessor.Start <Option <int> >(async inbox => { while (Interlocked.Read(ref received) < n) { var msgOpt = await inbox.TryReceive(timeout); if (msgOpt == null) { var numReceived = Interlocked.Read(ref received); if (numReceived % 100 == 0) { Trace.WriteLine(string.Format("timeout!, received = {0}", numReceived)); } } else { Interlocked.Increment(ref received); } } }); // When for (var i = 0; i < n; i++) { Thread.Sleep(1); mb.Post(Some(i)); } // Then while (Interlocked.Read(ref received) < n) { var numReceived = Interlocked.Read(ref received); if (numReceived % 100 == 0) { Trace.WriteLine(string.Format("received = {0}", numReceived)); } Thread.Sleep(1); } Assert.Equal(n, received); }
public CommandBus(IMessageQueueClient messageQueueClient, ILinearCommandManager linearCommandManager, string consumerId, string replyTopicName, string replySubscriptionName, ConsumerConfig consumerConfig = null) : base(messageQueueClient) { _consumerConfig = consumerConfig ?? ConsumerConfig.DefaultConfig; _consumerId = consumerId; _commandStateQueues = new ConcurrentDictionary <string, MessageState>(); _linearCommandManager = linearCommandManager; _replyTopicName = Configuration.Instance.FormatAppName(replyTopicName); _replySubscriptionName = Configuration.Instance.FormatAppName(replySubscriptionName); // _commandQueueNames = commandQueueNames; _messageProcessor = new MailboxProcessor(new DefaultProcessingMessageScheduler(), new OptionsWrapper <MailboxOption>(new MailboxOption { BatchCount = _consumerConfig.MailboxProcessBatchCount }), ObjectProviderFactory.GetService <ILoggerFactory>().CreateLogger <MailboxProcessor>()); }
public void TryReceive_timeout(int timeout) { // Given var mb = MailboxProcessor.Start <IReplyChannel <int?> >(async inbox => { var replyChannel = await inbox.TryReceive(); if (replyChannel == null) { Assert.True(false); return; } var msg2 = await inbox.TryReceive(timeout); replyChannel.Reply(msg2 == null ? 100 : 200); }); // When var result1 = mb.PostAndReply <int?>(channel => channel); // Then Assert.Equal(100, result1); }
public CommandProcessor(IMessageQueueClient messageQueueClient, IMessagePublisher messagePublisher, IHandlerProvider handlerProvider, string commandQueueName, string consumerId, ConsumerConfig consumerConfig = null) { ConsumerConfig = consumerConfig ?? ConsumerConfig.DefaultConfig; CommandQueueName = commandQueueName; HandlerProvider = handlerProvider; MessagePublisher = messagePublisher; ConsumerId = consumerId; CancellationTokenSource = new CancellationTokenSource(); MessageQueueClient = messageQueueClient; var loggerFactory = ObjectProviderFactory.GetService <ILoggerFactory>(); MessageProcessor = new MailboxProcessor(new DefaultProcessingMessageScheduler(), new OptionsWrapper <MailboxOption>(new MailboxOption { BatchCount = ConsumerConfig.MailboxProcessBatchCount }), loggerFactory.CreateLogger <MailboxProcessor>()); Logger = loggerFactory.CreateLogger(GetType().Name); }
// Token: 0x0600145A RID: 5210 RVA: 0x0007583C File Offset: 0x00073A3C private AssistantTaskContext CollectionStep(AssistantTaskContext context) { this.tracer.TraceFunction((long)this.GetHashCode(), "InferenceDataCollectionAssistant.CollectionStep"); ExAssert.RetailAssert(context != null, "Collection step invoked with a null task context"); StoreSession storeSession = context.Args.StoreSession; InferenceDataCollectionTaskContext inferenceDataCollectionTaskContext = context as InferenceDataCollectionTaskContext; ExAssert.RetailAssert(inferenceDataCollectionTaskContext != null, "Collection step invoked with an invalid task context. {0}", new object[] { context.GetType().FullName }); this.diagnosticLogger.LogInformation("Starting collection task. CollectionGuid={0}, Init={1}, Watermark={2}, MailboxGuid={3}, Name={4}", new object[] { inferenceDataCollectionTaskContext.MailboxProcessingState.CollectionGuid, inferenceDataCollectionTaskContext.MailboxProcessingState.IsInitialized, (inferenceDataCollectionTaskContext.MailboxProcessingState.Watermark == null) ? "None" : inferenceDataCollectionTaskContext.MailboxProcessingState.Watermark.DocumentId.ToString(), storeSession.MailboxGuid, storeSession.MailboxOwner.MailboxInfo.DisplayName }); Exception exception = null; MailboxProcessor.ProcessingResult processingResult; try { MailboxProcessor mailboxProcessor = new MailboxProcessor(this.collectionContext, storeSession, inferenceDataCollectionTaskContext.MailboxProcessingState); processingResult = mailboxProcessor.Process(); } catch (NonUniqueRecipientException ex) { processingResult = 1; exception = ex; } AssistantTaskContext result; if (processingResult == 2) { this.diagnosticLogger.LogInformation("Yielding collection task. CollectionGuid={0}, Init={1}, Watermark={2}, MailboxGuid={3}, Name={4}", new object[] { inferenceDataCollectionTaskContext.MailboxProcessingState.CollectionGuid, inferenceDataCollectionTaskContext.MailboxProcessingState.IsInitialized, (inferenceDataCollectionTaskContext.MailboxProcessingState.Watermark == null) ? "None" : inferenceDataCollectionTaskContext.MailboxProcessingState.Watermark.DocumentId.ToString(), storeSession.MailboxGuid, storeSession.MailboxOwner.MailboxInfo.DisplayName }); result = new InferenceDataCollectionTaskContext(context.MailboxData, context.Job, new AssistantStep(this.CollectionStep), inferenceDataCollectionTaskContext.MailboxProcessingState); } else { storeSession.Mailbox[MailboxSchema.InferenceDataCollectionProcessingState] = new byte[] { 1 }; storeSession.Mailbox.Save(); if (processingResult == 1) { this.diagnosticLogger.LogError("Failed collection task. CollectionGuid={0}, Init={1}, Watermark={2}, MailboxGuid={3}, Name={4}, Exception={5}", new object[] { inferenceDataCollectionTaskContext.MailboxProcessingState.CollectionGuid, inferenceDataCollectionTaskContext.MailboxProcessingState.IsInitialized, (inferenceDataCollectionTaskContext.MailboxProcessingState.Watermark == null) ? "None" : inferenceDataCollectionTaskContext.MailboxProcessingState.Watermark.DocumentId.ToString(), storeSession.MailboxGuid, storeSession.MailboxOwner.MailboxInfo.DisplayName, Util.StringizeException(exception) }); } else { this.diagnosticLogger.LogInformation("Finished collection task. CollectionGuid={0}, Init={1}, Watermark={2}, MailboxGuid={3}, Name={4}", new object[] { inferenceDataCollectionTaskContext.MailboxProcessingState.CollectionGuid, inferenceDataCollectionTaskContext.MailboxProcessingState.IsInitialized, (inferenceDataCollectionTaskContext.MailboxProcessingState.Watermark == null) ? "None" : inferenceDataCollectionTaskContext.MailboxProcessingState.Watermark.DocumentId.ToString(), storeSession.MailboxGuid, storeSession.MailboxOwner.MailboxInfo.DisplayName }); } result = null; } InferenceDataCollectionAssistant.PostInferenceDataCollectionProgressNotification(storeSession.MailboxGuid, processingResult.ToString()); if (processingResult == null) { InferenceDataCollectionAssistant.PostInferenceDataCollectionSuccessNotification(storeSession.MailboxGuid); } return(result); }