示例#1
0
        private Message BuildMsmqMessage(Int32 command, string descriptor, object message,
                                         IMessageEndpoint responseEndpoint, TimeSpan?timeToLive)
        {
            if (responseEndpoint != null && !(responseEndpoint is MsmqMessageEndpoint))
            {
                throw new NotSupportedException("MSMQ endpoints can only talk to each other!");
            }

            MessageQueue responseQueue = null;

            var msmqResponseEndpoint = responseEndpoint as MsmqMessageEndpoint;

            if (msmqResponseEndpoint != null)
            {
                responseQueue = msmqResponseEndpoint.MessageQueue;
            }

            var msmqMessage = new Message
            {
                AppSpecific   = (int)command,
                Body          = message,
                Formatter     = (IMessageFormatter)MessageFormatter.Clone(),
                Label         = descriptor,
                Recoverable   = true,
                ResponseQueue = responseQueue,
            };

            if (timeToLive.HasValue)
            {
                msmqMessage.TimeToBeReceived = timeToLive.Value;
            }
            return(msmqMessage);
        }
        public async Task DimeSchedulerClient_MessageEndpoint_ShouldCreate()
        {
            const string        uri           = "http://mydimescheduler.io";
            IAuthenticator      authenticator = new MockAuthenticator();
            DimeSchedulerClient client        = new(uri, authenticator);

            IMessageEndpoint endpoint = await client.Messages.Request();

            Assert.NotNull(endpoint);
        }
示例#3
0
        public async Task NotifyDown <T>(IMessageEndpoint <T> endpoint)
            where T : class
        {
            var receiveEndpoint = await _receiveEndpoint.Task.ConfigureAwait(false);

            await receiveEndpoint.CreatePublishEndpoint(_instanceAddress.Value).Publish <Down <T> >(new
            {
                endpoint.ServiceAddress,
                Endpoint = endpoint.EndpointInfo
            }).ConfigureAwait(false);
        }
示例#4
0
        public async Task NotifyUp <T>(IMessageEndpoint <T> endpoint)
            where T : class
        {
            var receiveEndpoint = await _receiveEndpoint.Task.ConfigureAwait(false);

            await receiveEndpoint.CreatePublishEndpoint(_instanceAddress.Value).Publish <Up <T> >(new
            {
                __CorrelationId = NewId.NextGuid(),
                endpoint.ServiceAddress,
                Endpoint = endpoint.EndpointInfo
            }).ConfigureAwait(false);
        }
示例#5
0
        public void ConfigureMessageEndpoint <T>(IMessageEndpoint <T> endpoint)
            where T : class
        {
            if (_messageTypes.ContainsKey(typeof(T)))
            {
                throw new ArgumentException($"The message type was already added by another service endpoint: {TypeMetadataCache<T>.ShortName}", nameof(T));
            }

            _messageTypes.Add(typeof(T), endpoint);

            _configurator.Consumer(() => new LinkConsumer <T>(endpoint));
        }
示例#6
0
        public async Task NotifyUp <T>(IMessageEndpoint <T> endpoint)
            where T : class
        {
            var receiveEndpoint = await _receiveEndpoint.Task.ConfigureAwait(false);

            var sendEndpoint = await receiveEndpoint.GetPublishSendEndpoint <Up <T> >().ConfigureAwait(false);

            await sendEndpoint.Send <Up <T> >(new
            {
                __CorrelationId = NewId.NextGuid(),
                endpoint.ServiceAddress,
                Endpoint = endpoint.EndpointInfo
            }).ConfigureAwait(false);
        }
示例#7
0
        public async Task NotifyDown <T>(IMessageEndpoint <T> endpoint)
            where T : class
        {
            var receiveEndpoint = await _receiveEndpoint.Task.ConfigureAwait(false);

            var initializeContext = await MessageInitializerCache <Down <T> > .Initialize(new
            {
                __CorrelationId = NewId.NextGuid(),
                endpoint.ServiceAddress,
                Endpoint = endpoint.EndpointInfo
            }).ConfigureAwait(false);

            await receiveEndpoint.CreatePublishEndpoint(_instanceAddress.Value).Publish(initializeContext.Message).ConfigureAwait(false);

            await endpoint.NotifyClients(receiveEndpoint, initializeContext.Message).ConfigureAwait(false);
        }
示例#8
0
        public void Send <TMessage>(TMessage message, IMessageEndpoint responseEndpoint = null, TimeSpan?timeToLive = null)
        {
            var msmqMessage = BuildMsmqMessage(
                MessageCommand,
                typeof(TMessage).Name,
                message,
                responseEndpoint,
                timeToLive
                );

            using (var transaction = new MessageQueueTransaction())
            {
                transaction.Begin();
                MessageQueue.Send(msmqMessage, transaction);
                transaction.Commit();
            }

            Trace.WriteLine(string.Format("Sent {0} message {1}", typeof(TMessage).Name, msmqMessage.Id));
        }
示例#9
0
        public async Task Execute()
        {
            try
            {
                IAuthenticator authenticator = new FormsAuthenticator
                                                   (DimeSchedulerCredentials.Uri,
                                                   DimeSchedulerCredentials.User,
                                                   DimeSchedulerCredentials.Password);

                DimeSchedulerClient client   = new(DimeSchedulerCredentials.Uri, authenticator);
                IMessageEndpoint    endpoint = await client.Messages.Request();

                await endpoint.PostAsync(new MessageRequest()
                {
                    Text = "Danger!", User = "******", Severity = Severity.Warning
                });
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.ToString());
            }
        }
示例#10
0
 public Program(string localUri, string remoteUri)
 {
     _localEndpoint = new MsmqMessageEndpoint(localUri);
     _remoteEndpoint = new MsmqMessageEndpoint(remoteUri);
 }
示例#11
0
        public void SendControlCommand(Int32 command, string descriptor, object message, IMessageEndpoint responseEndpoint = null, TimeSpan?timeToLive = null)
        {
            var msmqMessage = BuildMsmqMessage(command, descriptor, message, responseEndpoint, timeToLive);

            using (var transaction = new TransactionScope())
            {
                MessageQueue.Send(msmqMessage, MessageQueueTransactionType.Automatic);
                transaction.Complete();
            }

            Trace.WriteLine(string.Format("Sent command: {0}", command.ToString()));
        }
示例#12
0
 public ConductorMessageFilter(IMessageEndpoint <TMessage> endpoint)
 {
     _endpoint = endpoint;
 }
示例#13
0
 public Program(string localUri, string remoteUri)
 {
     _localEndpoint  = new MsmqMessageEndpoint(localUri);
     _remoteEndpoint = new MsmqMessageEndpoint(remoteUri);
 }
示例#14
0
 public LinkConsumer(IMessageEndpoint <T> messageEndpoint)
 {
     _messageEndpoint = messageEndpoint;
 }
示例#15
0
 public MessageViewModel(IMessageEndpoint messageEndpoint, ILoggedInUserModel loggedInUser, IMessagePostEndpoint messagePost)
 {
     _messageEndpoint     = messageEndpoint;
     _loggedInUser        = loggedInUser;
     _messagePostEndpoint = messagePost;
 }