// stop message publisher public async Task <IComponentHostServiceResponse <IMessagePublisherSettings> > StopMessagePublisherAsync() { var response = new ComponentHostServiceResponse <IMessagePublisherSettings>(); using (_logger.BeginScope("{Correlation}", HostInstanceId)) { if (MessagePublisher is null) { response.Set(MemberState.Error, "MessagePublisher not configured"); } else { try { await MessagePublisher.StopAsync(CancellationToken.None); response.Result = _messagePublisherSettings; } catch (Exception e) { _logger.LogError(e, "{Message} {@ObjectProperties}", "Failed to Stop MessagePublisher", Component); HostState = HostState.Errored; response.Set(MemberState.Error, "MessagePublisher failed to Stop"); } } } return(response); }
static void Main(string[] args) { int max = 50; CountdownEvent cd = new CountdownEvent(max); string endPoint = "tcp://localhost:5557"; System.Console.WriteLine("Publishing on {0}\n", endPoint); const string topic = "TestTopicxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"; { var publisher = new MessagePublisher<IMessage>("tcp://localhost:5557", new ProtoBufMessageSerializer(), topic); for (int i = 0; i < max; i++) { publisher.PublishAsync(new Message1AndItIs32CharactersLongForSureDefinitionForSure() { Id = i }); Thread.Sleep(TimeSpan.FromSeconds(0.5)); System.Console.WriteLine("Published: {0}", i); } } System.Console.WriteLine("[finished - any key to continue]"); System.Console.ReadKey(); }
static void Main(string[] args) { libs = new StorageController(); mPub = new MessagePublisher(); libs.GetLibrary(URL); libs.CreateBook(); mPub.MainAsync().GetAwaiter().GetResult(); }
public void PubSub() { var pub = new MessagePublisher(9200); var sub = new MessageSubscriber("localhost", 9200); pub.Close(); sub.Close(); }
public void TestMethod1() { var subscribeTask = new Task(ProcessMessagesFromQueue); subscribeTask.Start(); MessagePublisher.PublishApplicationMessage("test topic", "message"); }
void Publish <T>() { var type = typeof(T); MessagePublisher.Publish(new TransportMessage { CorrelationId = type.FullName }, new[] { type }); }
private static (Mock <IServiceProvider> mockServiceProvider, MessagePublisher uut) BuildTestContext() { var mockServiceProvider = new Mock <IServiceProvider>(); var uut = new MessagePublisher(mockServiceProvider.Object); return(mockServiceProvider, uut); }
public TestQueue(ILogger <MessagePublisher> publisherLogger, ILogger <MessageConsumer> consumerLogger) { _sqs = TestConfig.Config.GetAWSOptions("AWS_SQS").CreateServiceClient <IAmazonSQS>(); _sns = TestConfig.Config.GetAWSOptions("AWS_SNS").CreateServiceClient <IAmazonSimpleNotificationService>(); _messageOptions = TestConfig.Config.Get <MessageServiceOptions>(); MessagePublisher = new MessagePublisher(Options.Create(_messageOptions), publisherLogger, _sns); MessageConsumer = new MessageConsumer(Options.Create(_messageOptions), consumerLogger, _sqs, new NLogContext(), new List <ITypedHandler>(), _messageHistory); }
private void PingAppLauncherLoop() { while (true) { MessagePublisher.PingAppLauncher(); Task.Delay(1000).Wait(); } }
public void onPublisher(Post post) { MessagePublisher?.Invoke(this, new PostMessageEventArgs { Post = new Post { Message = post.Message } }); }
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 OneTimeSetUp() { var hostName = "localhost"; var exchangeName = ""; var queueName = "hello"; Consumer = new MessageConsumer(hostName, queueName); Publisher = new MessagePublisher(hostName, exchangeName, queueName); }
static void Main(string[] args) { users = new UserController(); mPub = new MessagePublisher(); users.GetLibrary(URL); mPub.MainAsync().GetAwaiter().GetResult(); }
public RestaurantService( MongoDbManager mgr, IMenuService menuService, MessagePublisher publisher, IHubContext <RestaurantHub> restaurantHub, RestaurantConnections restaurantConnections) { _restaurants = mgr.Restaurants; _menuService = menuService; _publisher = publisher; _restaurantHub = restaurantHub; _restaurantConnections = restaurantConnections; }
public void OneTimeSetUp() { var hostName = "localhost"; var exchangeName = ""; var queueName = "hello"; AutoConsumer = new AutoMessageConsumer(hostName, queueName); _publisher = new MessagePublisher(hostName, exchangeName, queueName); _autoResetEvent = new AutoResetEvent(false); }
public static IServiceCollection UseHangfireMessagePublisher( this IServiceCollection services, Action <IMessagePublisherConfigurator> configure) => services.AddSingleton <IMessagePublisher>( o => { var publisher = new MessagePublisher(o.GetService <IBackgroundJobClient>()); configure?.Invoke(publisher); return(publisher); });
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); }
/// <summary> /// /// </summary> protected void Application_Start() { AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); MessagePublisher.Start(); }
public void MessagePublisher_SendParticipantMessage() { _mockKafkaConfigHelper.Setup(p => p.ParticipantAllocationsTopicName).Returns("payday_participant_v1"); _mockKafkaPublisher.Setup(p => p.SendMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>())); var objectUnderTest = new MessagePublisher(_mockLogger.Object, _mockKafkaConfigHelper.Object, _mockKafkaPublisher.Object); bool success = objectUnderTest.SendParticipantAllocationsMessage(TestHelper.CreateCompMessage()); Assert.True(success); }
public NotificationCollection SaveShift(Shift shift) { var result = repository.Save(shift); if (!result.HasErrors()) { MessagePublisher.PublishApplicationMessage(MessageTopics.ShiftUpdated, shift.Id); } return(result); }
public static Configuration UseMessagePublisher(this Configuration configuration, string defaultTopic) { var container = IoCFactory.Instance.CurrentContainer; var messageQueueClient = IoCFactory.Resolve <IMessageQueueClient>(); defaultTopic = Configuration.Instance.FormatAppName(defaultTopic); var messagePublisher = new MessagePublisher(messageQueueClient, defaultTopic); container.RegisterInstance <IMessagePublisher>(messagePublisher); return(configuration); }
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 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 SerializesMessage() { Mock <IMessageSerializer> mockMessageSerializer = new Mock <IMessageSerializer>(); MessagePublisher <TestMessage> messagePublisher = new MessagePublisher <TestMessage>(Mock.Of <IMessagingEntityFactory>(), mockMessageSerializer.Object, Mock.Of <IMessagePropertyProvider <TestMessage> >(), Mock.Of <IMessageOutgoingPropertiesTable>()); TestMessage message = new TestMessage(); messagePublisher.PublishAsync(message); mockMessageSerializer.Verify(ms => ms.Serialize(It.IsAny <Stream>(), It.Is <TestMessage>(it => Object.ReferenceEquals(it, message))), Times.Once()); }
static async Task Main(string[] args) { var msgPublisher = new MessagePublisher(); while (true) { await msgPublisher.PublishAsync(); Thread.Sleep(TimeSpan.FromMilliseconds(100)); } // Console.WriteLine("Hello World!"); }
public string SendMessage(object sendMsgObj) { var client = new MessagePublisher(new MessagePublisherOptions() { AppKey = "123123", AppSecret = "sdfdsf", Gateway = "http://messagequene-gateway.i200.cn:9090/mq/publish" }); var result = client.SendMessage(sendMsgObj); return(result); }
public new void OneTimeSetUp() { base.OneTimeSetUp(); Publisher = new MessagePublisher(HostName, ExchangeName, CreatorQueueName); ConsumerCreator = new AutoConsumerCreator( new AutoMessageConsumer(HostName, CreatorQueueName), Creator); // Subscribe ConsumerCreator.EntryCreated += ConsumerCreator_EntryCreated; }
public new void OneTimeSetUp() { base.OneTimeSetUp(); Publisher = new MessagePublisher(HostName, ExchangeName, DeleterQueueName); ConsumerDeleter = new AutoConsumerDeleter( new AutoMessageConsumer(HostName, DeleterQueueName), Deleter); // Subscribe ConsumerDeleter.EntryDeleted += delegate { AutoResetEvent.Set(); }; }
public void MessagePublisher_CanSendMessage() { _configHelper.Setup(p => p.ParticipantTopicName).Returns(It.IsAny <string>()); _producer.Setup(p => p.SendMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>())); List <CompensationInvestment> invests = TestHelper.GenerateCompensationInvestments(); var objectUnderTest = new MessagePublisher(_loggerMock.Object, _configHelper.Object, _producer.Object); objectUnderTest.SendParticipantMessages(invests); _configHelper.Verify(p => p.ParticipantTopicName, Times.Once()); _producer.Verify(p => p.SendMessage(It.IsAny <string>(), It.IsAny <string>(), It.IsAny <Guid>()), Times.Exactly(5)); }
public static Configuration UseMessagePublisher(this Configuration configuration, string defaultTopic) { var builder = ObjectProviderFactory.Instance.ObjectProviderBuilder; builder.Register <IMessagePublisher>(provider => { var messageQueueClient = ObjectProviderFactory.GetService <IMessageQueueClient>(); configuration.SetDefaultTopic(defaultTopic); defaultTopic = configuration.FormatAppName(defaultTopic); var messagePublisher = new MessagePublisher(messageQueueClient, defaultTopic); return(messagePublisher); }, ServiceLifetime.Singleton); return(configuration); }
public async Task Should_send_messages_in_batch() { var resolverMock = new Mock <IPublisherClientResolver>(); var wrapperMock = new Mock <ITopicClientWrapper>(); resolverMock.Setup((_) => _.GetClient()).Returns(wrapperMock.Object); var publisher = new MessagePublisher(resolverMock.Object); await publisher.SendBatchAsync(new List <Message> { CreateEmptyMessage(), CreateEmptyMessage() }); wrapperMock.Verify((_) => _.SendAsync(It.IsAny <BrokeredMessage>()), Times.Exactly(2)); }
public void SerializesMessage() { Mock<IMessageSender> mockMessageSender = new Mock<IMessageSender>(); Mock<IMessageSerializer> mockMessageSerializer = new Mock<IMessageSerializer>(); Mock<IMessagePropertyProvider<TestMessage>> mockMessagePropertyProvider = new Mock<IMessagePropertyProvider<TestMessage>>(); MessagePublisher<TestMessage> messagePublisher = new MessagePublisher<TestMessage>(mockMessageSender.Object, mockMessageSerializer.Object, mockMessagePropertyProvider.Object); TestMessage message = new TestMessage(); messagePublisher.PublishAsync(message); mockMessageSerializer.Verify(ms => ms.Serialize(It.IsAny<Stream>(), It.Is<TestMessage>(it => Object.ReferenceEquals(it, message))), Times.Once()); }
public async Task GetsMessagePropertiesFromPropertyProviderAndAppliesThemToTheBrokeredMessage() { Mock<IMessageSender> mockMessageSender = new Mock<IMessageSender>(); BrokeredMessage brokeredMessageSent = null; mockMessageSender.Setup(ms => ms.SendAsync(It.IsAny<BrokeredMessage>())) .Callback<BrokeredMessage>(bm => { brokeredMessageSent = bm; }) .Returns(Task.FromResult<object>(null)); Mock<IMessageSerializer> mockMessageSerializer = new Mock<IMessageSerializer>(); Mock<IMessagePropertyProvider<TestMessage>> mockMessagePropertyProvider = new Mock<IMessagePropertyProvider<TestMessage>>(); KeyValuePair<string, object>[] properties = new[] { new KeyValuePair<string, object>("Prop1", 1), new KeyValuePair<string, object>("Prop2", "two"), }; mockMessagePropertyProvider.Setup(mpp => mpp.GetProperties(It.IsAny<TestMessage>())) .Returns(properties); MessagePublisher<TestMessage> messagePublisher = new MessagePublisher<TestMessage>(mockMessageSender.Object, mockMessageSerializer.Object, mockMessagePropertyProvider.Object); TestMessage message = new TestMessage(); await messagePublisher.PublishAsync(message); mockMessagePropertyProvider.Verify(mpp => mpp.GetProperties(It.Is<TestMessage>(it => Object.ReferenceEquals(it, message))), Times.Once); brokeredMessageSent.Should().NotBeNull(); // TODO: should be able to do this cleaner brokeredMessageSent.Properties.Should().ContainKeys(properties.Select(kvp => kvp.Key), "Should have translated all properties provided by the property provider to the BrokeredMessage."); brokeredMessageSent.Properties.Should().ContainValues(properties.Select(kvp => kvp.Value), "Should have translated all properties provided by the property provider to the BrokeredMessage."); }
public async Task RequestRequesterIdEndsUpAsReplyToSessionId() { Mock<IMessageSender> mockMessageSender = new Mock<IMessageSender>(); BrokeredMessage brokeredMessageSent = null; mockMessageSender.Setup(ms => ms.SendAsync(It.IsAny<BrokeredMessage>())) .Callback<BrokeredMessage>(bm => { brokeredMessageSent = bm; }) .Returns(Task.FromResult<object>(null)); Mock<IMessageSerializer> mockMessageSerializer = new Mock<IMessageSerializer>(); Mock<IMessagePropertyProvider<TestMessage>> mockMessagePropertyProvider = new Mock<IMessagePropertyProvider<TestMessage>>(); MessagePublisher<TestMessage> messagePublisher = new MessagePublisher<TestMessage>(mockMessageSender.Object, mockMessageSerializer.Object, mockMessagePropertyProvider.Object); TestRequest request = new TestRequest { RequesterId = "TestRequesterId" }; await messagePublisher.PublishAsync(request); mockMessageSender.Verify(ms => ms.SendAsync(It.IsAny<BrokeredMessage>()), Times.Once()); brokeredMessageSent.Should().NotBeNull(); brokeredMessageSent.ReplyToSessionId.Should().Be(request.RequesterId); }
public async Task SendsMessage() { Mock<IMessageSender> mockMessageSender = new Mock<IMessageSender>(); Mock<IMessageSerializer> mockMessageSerializer = new Mock<IMessageSerializer>(); Mock<IMessagePropertyProvider<TestMessage>> mockMessagePropertyProvider = new Mock<IMessagePropertyProvider<TestMessage>>(); MessagePublisher<TestMessage> messagePublisher = new MessagePublisher<TestMessage>(mockMessageSender.Object, mockMessageSerializer.Object, mockMessagePropertyProvider.Object); TestMessage message = new TestMessage(); await messagePublisher.PublishAsync(message); mockMessageSender.Verify(ms => ms.SendAsync(It.IsAny<BrokeredMessage>()), Times.Once()); }
public async Task AppliesMessageTypeNamePropertyToTheBrokeredMessage() { Mock<IMessageSender> mockMessageSender = new Mock<IMessageSender>(); BrokeredMessage brokeredMessageSent = null; mockMessageSender.Setup(ms => ms.SendAsync(It.IsAny<BrokeredMessage>())) .Callback<BrokeredMessage>(bm => { brokeredMessageSent = bm; }) .Returns(Task.FromResult<object>(null)); Mock<IMessageSerializer> mockMessageSerializer = new Mock<IMessageSerializer>(); Mock<IMessagePropertyProvider<TestMessage>> mockMessagePropertyProvider = new Mock<IMessagePropertyProvider<TestMessage>>(); MessagePublisher<TestMessage> messagePublisher = new MessagePublisher<TestMessage>(mockMessageSender.Object, mockMessageSerializer.Object, mockMessagePropertyProvider.Object); TestMessage message = new TestMessage(); await messagePublisher.PublishAsync(message); brokeredMessageSent.Should().NotBeNull(); brokeredMessageSent.Properties.Should().Contain(new KeyValuePair<string,object>(MessagePropertyNames.TypeName, typeof(TestMessage).Name), "Should have applied the mesage type name property to the BrokeredMessage."); }
public async Task ShouldCorrectlyPublishAndSubscribeToMulipleMultiplexedTopics() { const string brokerUri = "tcp://localhost:61616"; const string topicName1 = "Obvs.Tests.ShouldCorrectlyPublishAndSubscribeToMulipleMultiplexedTopics1"; const string topicName2 = "Obvs.Tests.ShouldCorrectlyPublishAndSubscribeToMulipleMultiplexedTopics2"; IMessagePropertyProvider<IMessage> getProperties = new DefaultPropertyProvider<IMessage>(); IConnectionFactory connectionFactory = new ConnectionFactory(brokerUri); var lazyConnection = new Lazy<IConnection>(() => { var conn = connectionFactory.CreateConnection(); conn.Start(); return conn; }); IMessagePublisher<IMessage> publisher1 = new MessagePublisher<IMessage>( lazyConnection, new ActiveMQTopic(topicName1), new JsonMessageSerializer(), getProperties, _testScheduler); IMessagePublisher<IMessage> publisher2 = new MessagePublisher<IMessage>( lazyConnection, new ActiveMQTopic(topicName2), new JsonMessageSerializer(), getProperties, _testScheduler); IMessageDeserializer<IMessage>[] deserializers = { new JsonMessageDeserializer<TestMessage>(), new JsonMessageDeserializer<TestMessage2>() }; IMessageSource<IMessage> source = new MergedMessageSource<IMessage>(new[] { new MessageSource<IMessage>( lazyConnection, deserializers, new ActiveMQTopic(topicName1)), new MessageSource<IMessage>( lazyConnection, deserializers, new ActiveMQTopic(topicName2)) }); source.Messages.Subscribe(Console.WriteLine); await publisher1.PublishAsync(new TestMessage { Id = 1234 }); await publisher1.PublishAsync(new TestMessage2 { Id = 4567 }); await publisher2.PublishAsync(new TestMessage { Id = 8910 }); await publisher2.PublishAsync(new TestMessage2 { Id = 1112 }); Thread.Sleep(TimeSpan.FromSeconds(3)); }