CodeSharp.EventSourcing.MsmqUtilities.GetReturnAddress C# (CSharp) Метод

GetReturnAddress() публичный статический Метод

Gets the name of the return address from the provided value. If the target includes a machine name, uses the local machine name in the returned value otherwise uses the local IP address in the returned value.
public static GetReturnAddress ( Address value, Address target ) : string
value Address
target Address
Результат string
        public static string GetReturnAddress(Address value, Address target)
        {
            var machine = target.Machine;

            IPAddress targetIpAddress;

            //see if the target is an IP address, if so, get our own local ip address
            if (IPAddress.TryParse(machine, out targetIpAddress))
            {
                if (string.IsNullOrEmpty(localIp))
                {
                    localIp = LocalIpAddress(targetIpAddress);
                }
                return PREFIX_TCP + localIp + PRIVATE + value.Queue;
            }

            return PREFIX + GetFullPathWithoutPrefix(value);
        }

Same methods

MsmqUtilities::GetReturnAddress ( string value, string target ) : string

Usage Example

        void IMessageTransport.SendMessage(Message message, Address targetAddress)
        {
            if (message == null)
            {
                throw new ArgumentNullException("message");
            }
            if (targetAddress == null)
            {
                throw new ArgumentNullException("targetAddress");
            }

            var queuePath = MsmqUtilities.GetFullPath(targetAddress);

            try
            {
                using (var messageQueue = new MessageQueue(queuePath, QueueAccessMode.SendAndReceive))
                {
                    var toSend = MsmqUtilities.Convert(message);

                    if (message.ReplyToAddress != null)
                    {
                        toSend.ResponseQueue = new MessageQueue(MsmqUtilities.GetReturnAddress(message.ReplyToAddress.ToString(), targetAddress.ToString()));
                    }

                    messageQueue.Send(toSend, MessageQueueTransactionType.Automatic);

                    message.Id = toSend.Id;
                }
            }
            catch (MessageQueueException ex)
            {
                if (ex.MessageQueueErrorCode == MessageQueueErrorCode.QueueNotFound)
                {
                    throw new EventSourcingException("消息队列未找到: [{0}]", targetAddress);
                }
                else
                {
                    throw new EventSourcingException("发送消息到队列时遇到异常,队列地址:{0},异常详情:{1}", targetAddress, ex);
                }
            }
            catch (Exception ex)
            {
                throw new EventSourcingException("发送消息到队列时遇到异常,队列地址:{0},异常详情:{1}", targetAddress, ex);
            }
        }