private void RegisterReplyMessageCorrelator() { lock (_replyMessageCorrelatorMonitor) { if (_replyMessageCorrelator != null) { return; } AbstractEndpoint correlator = null; IMessageHandler handler = new LocalReplyProducingMessageHandler(); if (_replyChannel is ISubscribableChannel) { correlator = new EventDrivenConsumer((ISubscribableChannel)_replyChannel, handler); } else if (_replyChannel is IPollableChannel) { PollingConsumer endpoint = new PollingConsumer( (IPollableChannel)_replyChannel, handler); endpoint.Trigger = new IntervalTrigger(TimeSpan.FromMilliseconds(10)); endpoint.ObjectFactory = ObjectFactory; endpoint.AfterPropertiesSet(); correlator = endpoint; } if (IsRunning) { if (correlator == null) { throw new InvalidOperationException("correlator must not be null"); } ((ILifecycle)correlator).Start(); } _replyMessageCorrelator = correlator; } }
public void Subscription() { TestUtils.TestApplicationContext context = TestUtils.CreateTestApplicationContext(); SynchronousQueue <string> queue = new SynchronousQueue <string>(); TestBean testBean = new TestBean(queue); QueueChannel channel = new QueueChannel(); context.RegisterChannel("channel", channel); Message <string> message = new Message <string>("testing"); channel.Send(message); string polledString; Assert.IsFalse(queue.Poll(out polledString)); MethodInvokingMessageHandler handler = new MethodInvokingMessageHandler(testBean, "foo"); PollingConsumer endpoint = new PollingConsumer(channel, handler); endpoint.Trigger = new IntervalTrigger(TimeSpan.FromMilliseconds(10)); context.RegisterEndpoint("testEndpoint", endpoint); context.Refresh(); string result; Assert.IsTrue(queue.Poll(TimeSpan.FromMilliseconds(1000), out result)); Assert.IsNotNull(result); Assert.That(result, Is.EqualTo("testing")); context.Stop(); }
public void Default() { XmlApplicationContext ctx = (XmlApplicationContext)NmsTestUtils.GetContext(@"Nms\Config\NmsOutboundGatewayWithConverter.xml"); PollingConsumer endpoint = (PollingConsumer)ctx.GetObject("nmsGateway"); // NmsOutboundGateway._handler. object messageConverter = TestUtils.GetFieldValue(TestUtils.GetFieldValue(endpoint, "_handler"), "messageConverter"); Assert.That(messageConverter, Is.InstanceOf(typeof(StubMessageConverter))); }
public void SetUp() { requestChannel = new QueueChannel(); context.RegisterChannel("requestChannel", requestChannel); TestReplyProducingMessageHandler handler = new TestReplyProducingMessageHandler(); PollingConsumer endpoint = new PollingConsumer(requestChannel, handler); endpoint.Trigger = new IntervalTrigger(new TimeSpan(0, 0, 0, 0, 10)); context.RegisterEndpoint("testEndpoint", endpoint); context.Refresh(); }
public void Init() { _consumer.Counter.Value = 0; _trigger.Reset(); _channelMock = _mocks.StrictMock <IPollableChannel>(); _endpoint = new PollingConsumer(_channelMock, _consumer); _endpoint.TaskScheduler = _taskScheduler; _taskScheduler.ErrorHandler = _errorHandler; _taskScheduler.Start(); _endpoint.Trigger = _trigger; _endpoint.ReceiveTimeout = TimeSpan.FromMilliseconds(-1); //reset(_channelMock); }
private void InitializeEndpoint() { lock (_initializationMonitor) { if (_initialized) { return; } AssertUtils.ArgumentHasText(_inputChannelName, "inputChannelName is required"); AssertUtils.IsTrue(_objectFactory.ContainsObject(_inputChannelName), "no such input channel '" + _inputChannelName + "' for endpoint '" + _objectName + "'"); IMessageChannel channel = (IMessageChannel)_objectFactory.GetObject(_inputChannelName, typeof(IMessageChannel)); if (channel is ISubscribableChannel) { if (_pollerMetadata != null) { throw new ArgumentException("A poller should not be specified for endpoint '" + _objectName + "', since '" + _inputChannelName + "' is a SubscribableChannel (not pollable)."); } _endpoint = new EventDrivenConsumer((ISubscribableChannel)channel, _handler); } else if (channel is IPollableChannel) { PollingConsumer pollingConsumer = new PollingConsumer((IPollableChannel)channel, _handler); if (_pollerMetadata == null) { _pollerMetadata = IntegrationContextUtils.GetDefaultPollerMetadata(_objectFactory); AssertUtils.ArgumentNotNull(_pollerMetadata, "No poller has been defined for endpoint '" + _objectName + "', and no default poller is available within the context."); } pollingConsumer.Trigger = _pollerMetadata.Trigger; pollingConsumer.MaxMessagesPerPoll = _pollerMetadata.MaxMessagesPerPoll; pollingConsumer.ReceiveTimeout = _pollerMetadata.ReceiveTimeout; pollingConsumer.TaskExecutor = _pollerMetadata.TaskExecutor; pollingConsumer.TransactionManager = _pollerMetadata.TransactionManager; pollingConsumer.TransactionDefinition = _pollerMetadata.TransactionDefinition; pollingConsumer.AdviceChain = _pollerMetadata.AdviceChain; _endpoint = pollingConsumer; } else { throw new ArgumentException("unsupported channel type: [" + channel.GetType() + "]"); } _endpoint.AutoStartup = _autoStartup; _endpoint.ObjectName = _objectName; _endpoint.ObjectFactory = _objectFactory; _endpoint.AfterPropertiesSet(); _initialized = true; } }
static void Main(string[] args) { // SampleSubject ss = new SampleSubject(); // ss.Source.OnNext(1); // ss.Source.OnNext(1); // ss.Source.OnNext(1); // ss.Source.OnNext(1); // var item = Console.ReadLine(); // if (item == "q") // { // ss.Source.Dispose(); // } PollingConsumer pc = new PollingConsumer(); CancellationToken ct = new CancellationToken(); var obs = pc.StartConsuming(ct, TimeSpan.FromSeconds(1)); var dis = obs.Subscribe(sub => { Console.WriteLine(sub); Console.WriteLine(Thread.CurrentThread.ManagedThreadId); Console.WriteLine(Thread.CurrentThread.Name); //Consumer Console.WriteLine(Thread.CurrentThread.IsThreadPoolThread); //False }, () => { Console.WriteLine("Complete"); }); var stop = Console.ReadLine(); if (stop == "q") { dis.Dispose(); Console.WriteLine(ct.IsCancellationRequested); //false as token is not cancelled on sidpose } // SampleForEvent se = new SampleForEvent(); // se.OnEvent += new MyEventHandler(MaxReached); // se.AddToNumber(2); // se.AddToNumber(9); // se.AddToNumber(4); // int[] items = {1,2,3,4,5}; // UnderstandingValueType uvt = new UnderstandingValueType(); // Console.WriteLine(items[0]); }