public void Monitor_subscription_disposal_stops_subscription() { var observed = new List <Device>(); var monitor = new MessagePublisher <Device>(); using (var _ = monitor.Subscribe(observed.Add)) { monitor.Publish(TestMessages.NewSearchResponse()); } monitor.Publish(TestMessages.NewSearchResponse()); observed.Count.Should().Be(1); }
protected override async Task HandleMessage(PiCalcMessage msg) { Console.WriteLine($"Started processing task {msg.Id}, " + $"task name: {msg.Name}, " + $"precision: {msg.Precision}..."); subscriptionHandler.Register(msg.Id); var result = piCalcService.Calculate( msg.Precision, () => subscriptionHandler.IsStopped(msg.Id)); var publisher = new MessagePublisher <PiCalcResultMessage>(busClient); await publisher.Publish( new PiCalcResultMessage { Id = msg.Id, Pi = result.ToString() }); Console.WriteLine($"Calculated PI (task Id: {msg.Id}, " + $"task name: {msg.Name}, " + $"precision: {msg.Precision}) : " + $"{result.ToString()}"); }
void Publish <T>() { var type = typeof(T); MessagePublisher.Publish(new TransportMessage { CorrelationId = type.FullName }, new[] { type }); }
void Publish(TransportMessage messageToSend, PublishOptions publishOptions) { if (MessagePublisher == null) { throw new InvalidOperationException("No message publisher has been registered. If you're using a transport without native support for pub/sub please enable the message driven publishing feature by calling config.EnableFeature<MessageDrivenSubscriptions>() in your configuration"); } MessagePublisher.Publish(messageToSend, publishOptions); }
public void Monitor_publishes_devices_to_observers() { var observed = new List <Device>(); var monitor = new MessagePublisher <Device>(); monitor.Subscribe(observed.Add); monitor.Publish(TestMessages.NewSearchResponse()); observed.Count.Should().Be(1); }
public void Flow_single_type() { var aggregator = new MessageAggregator(); var publisher = new MessagePublisher(aggregator); aggregator.Subscribe(new DoNothingHandler()); for (var i = 0; i < trials; i++) { publisher.Publish(new BaseMessage()); } }
public void Publishes_to_manifold_handler() { var aggregator = new MessageAggregator(); var publisher = new MessagePublisher(aggregator); var handler = new ManifoldMessageHandler(); aggregator.Subscribe(handler); var sent = publisher.Publish(new StringMessage("Foo")); Assert.True(sent); Assert.Equal(1, handler.HandledString); Assert.Equal(0, handler.HandledInteger); sent = publisher.Publish(new IntegerMessage(123)); Assert.True(sent); Assert.Equal(1, handler.HandledString); Assert.Equal(1, handler.HandledInteger); }
public void Flow_manifold_type() { var aggregator = new MessageAggregator(); var publisher = new MessagePublisher(aggregator); aggregator.Subscribe(new ManifoldHandler()); for (var i = 0; i < trials; i++) { publisher.Publish(new SubMessage()); } }
public async Task <ActionResult> PublishItem([FromBody] ItemToReturnDto request) { var itemCreated = new ItemForServBus { Id = request.Id, Name = request.Name, Description = request.Description, OldPrice = request.OldPrice, NewPrice = request.NewPrice, Discount = request.Discount, RatingsCount = request.RatingsCount, RatingsValue = request.RatingsValue, availibilityCount = request.availibilityCount, cartCount = request.cartCount, Weight = request.Weight, CategoryId = request.CategoryId, BrandName = request.BrandName }; await _messagePublisher.Publish(itemCreated); return(Ok()); }
public void Publishes_to_handler() { var aggregator = new MessageAggregator(); var publisher = new MessagePublisher(aggregator); var handled = 0; aggregator.Subscribe <StringMessage>(se => { handled++; }); var sent = publisher.Publish(new StringMessage("Foo")); Assert.True(sent); Assert.Equal(1, handled); }
public void Can_subscribe_with_manifold_hierarchical_consumer() { var aggregator = new MessageAggregator(); var publisher = new MessagePublisher(aggregator); var handler = new ManifoldHierarchicalMessageHandler(); aggregator.Subscribe(handler); var sent = publisher.Publish(new InheritedMessage()); Assert.True(sent); Assert.Equal(1, handler.HandledInterface); Assert.Equal(1, handler.HandledBase); Assert.Equal(1, handler.HandledInherited); }
public void Publishes_to_multiple_handlers() { var aggregator = new MessageAggregator(); var publisher = new MessagePublisher(aggregator); var handler1 = 0; var handler2 = 0; aggregator.Subscribe <StringMessage>(e => { handler1++; }); aggregator.Subscribe <StringMessage>(e => { handler2++; }); var sent = publisher.Publish(new StringMessage("Foo")); Assert.True(sent); Assert.Equal(1, handler1); Assert.Equal(1, handler2); }
public void Post([FromBody] PublishConfiguration publishConfiguration) { foreach (var item in _context.channelOnboard) { MessagePublisher mp = new MessagePublisher(item.sourceName, publishConfiguration.sourceNotificationInterval); var subscriber = _context.subscriberOnboard.Where(s => s.ChannelId == item.Id).FirstOrDefault(); if (subscriber != null) { MessageSubscriber sub1 = new MessageSubscriber(subscriber.SubEmail, subscriber.Category); sub1.Subscribe(mp); mp.Publish(); IntrimData.SetData(mp.GetAllNotification()); //_context.notificationQueue.AddRange(mp.GetAllNotification()); //_context.SaveChanges(); } } }
public void WithValidCode_ThenDontCrash() { var code = @" public class Foo {} "; TotalTestsResult result = new TotalTestsResult(); _messager.OfType <ResponseMessage>() .Subscribe(x => { result = (TotalTestsResult)x.Data; }); _messager.Publish(new RequestMessage("compileRequest", "senderId", new { Code = code })); result.Message.Should().Be("a"); }
/// <summary> /// Removes the value with the given key. /// </summary> /// <param name="key">A string identifying the requested value.</param> public void Remove(string key) { var semaphore = GetOrCreateLock(key, null); semaphore.Wait(); try { L2Cache.Remove(key); L1Cache.Remove( $"{L1L2RedisCacheOptions.KeyPrefix}{key}"); MessagePublisher.Publish(key); L1Cache.Remove( $"{L1L2RedisCacheOptions.LockKeyPrefix}{key}"); } finally { semaphore.Release(); } }
/// <summary> /// Sets a value with the given key. /// </summary> /// <param name="key">A string identifying the requested value.</param> /// <param name="value">The value to set in the cache.</param> /// <param name="distributedCacheEntryOptions">The cache options for the value.</param> public void Set( string key, byte[] value, DistributedCacheEntryOptions distributedCacheEntryOptions) { var semaphore = GetOrCreateLock( key, distributedCacheEntryOptions); semaphore.Wait(); try { L2Cache.Set( key, value, distributedCacheEntryOptions); SetMemoryCache( key, value, distributedCacheEntryOptions); MessagePublisher.Publish(key); } finally { semaphore.Release(); } }
/// <summary> /// Removes the value with the given key. /// </summary> /// <param name="key">A string identifying the requested value.</param> /// <param name="cancellationToken">Optional. The System.Threading.CancellationToken used to propagate notifications that the operation should be canceled.</param> /// <returns>The System.Threading.Tasks.Task that represents the asynchronous operation.</returns> public async Task RemoveAsync( string key, CancellationToken cancellationToken = default) { var semaphore = await GetOrCreateLockAsync( key, null, cancellationToken); await semaphore.WaitAsync(cancellationToken); try { L2Cache.Remove(key); L1Cache.Remove( $"{L1L2RedisCacheOptions.KeyPrefix}{key}"); MessagePublisher.Publish(key); L1Cache.Remove( $"{L1L2RedisCacheOptions.LockKeyPrefix}{key}"); } finally { semaphore.Release(); } }
public void Test() { const string rootDirectory = "C:\\Temp"; IMessageSource <IMessage> source = new MessageSource <IMessage>(new SequencedDirectory(rootDirectory), new List <IMessageDeserializer <IMessage> > { new JsonMessageDeserializer <TestMessage>() }, new EventLoopScheduler()); source.Messages.Subscribe(Console.WriteLine, ex => Console.WriteLine(ex)); IMessagePublisher <IMessage> publisher = new MessagePublisher <IMessage>(new SequencedDirectory(rootDirectory), new JsonMessageSerializer(), new EventLoopScheduler()); for (int i = 0; i < 20; ++i) { publisher.Publish(new TestMessage { Data = string.Format("Blah{0}", i) }); } source.Messages.Take(20).Wait(); }
public void Create(IEnumerable <YdhlBryzxx> bryzxxes) { MessagePublisher.Publish(new BryzxxCreatedMessage(bryzxxes)); }
public void Create(YdhlJbxx jbxx) { MessagePublisher.Publish(new JbxxCreatedMessage(jbxx)); }
public void Create(YdhlBrxz brxz) { MessagePublisher.Publish(new BrxzCreatedMessage(brxz)); }
public void Create(YdhlBrzd brzd) { MessagePublisher.Publish(new BrzdCreatedMessage(brzd)); }
public void Create(IEnumerable <YdhlJcbg> jcbgs) { MessagePublisher.Publish(new JcbgCreatedMessage(jcbgs)); }
public void Create(YdhlJbbm jbbm) { MessagePublisher.Publish(new JbbmCreatedMessage(jbbm)); }
public void Create(IEnumerable <YdhlTwd> twds) { MessagePublisher.Publish(new TwdCreatedMessage(twds)); }
public void Invoke(SendPhysicalMessageContext context, Action next) { var sendOptions = context.SendOptions; var logicalMessage = context.LogicalMessages.FirstOrDefault(); var messageDescription = "ControlMessage"; if (logicalMessage != null) { messageDescription = logicalMessage.MessageType.FullName; } try { if (sendOptions.Intent == MessageIntentEnum.Publish) { if (MessagePublisher == null) { throw new InvalidOperationException("No message publisher has been registered. If you're using a transport without native support for pub/sub please enable the message driven publishing feature by calling: Feature.Enable<MessageDrivenPublisher>() in your configuration"); } var eventTypesToPublish = context.LogicalMessages.SelectMany(m => m.Metadata.MessageHierarchy) .Distinct() .ToList(); var subscribersFound = MessagePublisher.Publish(context.MessageToSend, eventTypesToPublish); context.Set("SubscribersFound", subscribersFound); } else { var deliverAt = DateTime.UtcNow; if (sendOptions.DelayDeliveryWith.HasValue) { deliverAt = deliverAt + sendOptions.DelayDeliveryWith.Value; } if (sendOptions.DeliverAt.HasValue) { deliverAt = sendOptions.DeliverAt.Value.ToUniversalTime(); } if (deliverAt > DateTime.UtcNow) { context.MessageToSend.Headers[Headers.IsDeferredMessage] = true.ToString(); SetDelayDeliveryWithHeader(context, sendOptions.DelayDeliveryWith); MessageDeferral.Defer(context.MessageToSend, deliverAt, sendOptions.Destination); } else { MessageSender.Send(context.MessageToSend, sendOptions.Destination); } } } catch (QueueNotFoundException ex) { throw new ConfigurationErrorsException("The destination queue '" + ex.Queue + "' could not be found. You may have misconfigured the destination for this kind of message (" + messageDescription + ") in the MessageEndpointMappings of the UnicastBusConfig section in your configuration file. " + "It may also be the case that the given queue just hasn't been created yet, or has been deleted." , ex); } if (Log.IsDebugEnabled) { Log.Debug(string.Format("Sending message {0} with ID {1} to destination {2}.\n" + "ToString() of the message yields: {3}\n" + "Message headers:\n{4}", messageDescription, context.MessageToSend.Id, sendOptions.Destination, logicalMessage != null ? logicalMessage.ToString() : "", string.Join(", ", context.MessageToSend.Headers.Select(h => h.Key + ":" + h.Value).ToArray()) )); } next(); }
internal void TestPublish(TestMessage v) { _publisher.Publish(v); }
public void Create(YdhlYpzd zd) { MessagePublisher.Publish(new YpzdCreatedMessage(zd)); }
public void Create(YdhlYpyf ypyf) { MessagePublisher.Publish(new YpyfCreatedMessage(ypyf)); }