예제 #1
0
        protected override bool TryRemoveCancelTokenSource(string key, bool successive, out CancellationTokenSource source)
        {
            var removed = base.TryRemoveCancelTokenSource(key, successive, out source);

            // "removed = false" means: the token either did not exist OR was not created by this node.
            // "successive" means: a messagebus subscriber has called this method

            if (!removed && !successive)
            {
                // This server possibly did not create the cancellation token.
                // Call other nodes and let THEM try to remove.

                Logger.Debug($"AsyncState posts '{key}' message to other nodes for state removal.");
                _bus.Publish(Channel, "removects^" + key);
                return(true); // TBD: really true?
            }

            return(removed);
        }
        public void CanSendMessage()
        {
            if (_messageBus == null)
            {
                return;
            }

            var resetEvent = new AutoResetEvent(false);

            _messageBus.Subscribe <SimpleMessageA>(msg => {
                Assert.Equal("Hello", msg.Data);
                resetEvent.Set();
            });
            _messageBus.Publish(new SimpleMessageA {
                Data = "Hello"
            });

            bool success = resetEvent.WaitOne(15000);

            Assert.True(success, "Failed to receive message.");
        }