protected override Task OnStart(IMessageSession context)
    {
        var mainLogicalAddress = settings.LogicalAddress();
        var endpointInstance   = mainLogicalAddress.EndpointInstance;
        var instanceProperties = endpointInstance.Properties.ToDictionary(kvp => kvp.Key, kvp => kvp.Value);

        instanceProperties["queue"] = endpointInstance.Endpoint;
        publication = new RoutingInfo
        {
            EndpointName          = settings.EndpointName(),
            Discriminator         = endpointInstance.Discriminator,
            InstanceProperties    = instanceProperties,
            HandledMessageTypes   = hanledMessageTypes.Select(m => m.AssemblyQualifiedName).ToArray(),
            PublishedMessageTypes = publishedMessageTypes.Select(m => m.AssemblyQualifiedName).ToArray(),
            Active = true,
        };

        timer = new Timer(
            callback: state =>
        {
            Publish()
            .ConfigureAwait(false)
            .GetAwaiter()
            .GetResult();
        },
            state: null,
            dueTime: TimeSpan.Zero,
            period: heartbeatPeriod);

        return(Publish());
    }
示例#2
0
        /// <summary>
        /// Retreive routing info for the supplied topic.
        /// </summary>
        /// <param name="topic">The topic for which routing is being retreived</param>
        /// <returns>RoutingInfo or null</returns>
        public RoutingInfo RetrieveRoutingInfo(string topic)
        {
            Log.DebugFormat("Getting routing info for topic {0}", topic);

            // the routing that we'll return
            RoutingInfo routing = null;

            // take the template expression provided by the user and create
            // the complete URL of the GTS
            string urlString = string.Format(_urlExpression, topic);

            // log the url for debugging purposes
            Log.DebugFormat("Calling GTS with url {0}", urlString);

            try
            {
                // use the web request factory to create a web request
                WebRequest request = _webRequestFactory.CreateRequest(urlString);

                // get some response to the request
                using (Stream responseStream = request.GetResponse().GetResponseStream())
                {
                    routing = _serializer.Deserialize(responseStream);
                }
            }
            catch (Exception ex)
            {
                Log.Error("Failed to get RoutingInfo from the GTS.", ex);
            }

            return(routing);
        }
示例#3
0
        public void Send(Envelope env)
        {
            Log.Debug("Enter Send");

            // first, get the topology based on the headers
            RoutingInfo routing = this.GetRoutingFromCacheOrService(_routingInfoCache, _topoSvc, env.Headers);

            // next, pull out all the producer exchanges
            IEnumerable <Exchange> exchanges =
                from route in routing.Routes
                select route.ProducerExchange;

            // for each exchange, send the envelope
            foreach (Exchange ex in exchanges)
            {
                Log.Debug("Sending to exchange: " + ex.ToString());
                IConnection conn = _connFactory.ConnectTo(ex);

                using (IModel channel = conn.CreateModel())
                {
                    IBasicProperties props = channel.CreateBasicProperties();
                    props.Headers = env.Headers as IDictionary;

                    channel.ExchangeDeclare(ex.Name, ex.ExchangeType, ex.IsDurable, ex.IsAutoDelete, ex.Arguments);
                    channel.BasicPublish(ex.Name, ex.RoutingKey, props, env.Payload);

                    // close the channel, but not the connection.  Channels are cheap.
                    channel.Close();
                }
            }

            Log.Debug("Leave Send");
        }
示例#4
0
        //需要调用窗体名称
        System.Windows.Forms.Control INetUserControl.CreateControl(UFSoft.U8.Framework.Login.UI.clsLogin login, string MenuID, string Paramters)
        {
            UFSoft.U8.Framework.LoginContext.UserData LoginInfo = new UFSoft.U8.Framework.LoginContext.UserData();
            LoginInfo = login.GetLoginInfo();
            string conn = LoginInfo.ConnString;

            conn = Utils.ConvertConn(conn);
            DbHelperSQL.connectionString = conn;

            string sLogUserid   = LoginInfo.UserId;
            string sLogUserName = LoginInfo.UserName;
            string sLogDate     = LoginInfo.operDate;
            string sAccID       = LoginInfo.AccID;

            ClsUserRight clsUser = new ClsUserRight();

            if (clsUser.chkRight(login, "TH_8"))
            {
                RoutingInfo fm = new RoutingInfo();
                fm.Conn      = conn;
                fm.sUserID   = sLogUserid;
                fm.sUserName = sLogUserName;
                fm.sLogDate  = sLogDate;
                fm.sAccID    = sAccID;

                this._Title = "Routing Info";

                return(fm);
            }
            else
            {
                MessageBox.Show("no rights");
                return(null);
            }
        }
示例#5
0
        public RoutingInfo GetRoutingInfo(IDictionary <string, string> routingHints)
        {
            // the routing we'll return
            RoutingInfo routing = null;


            // get the topic from the routing hints
            string topic = routingHints[EnvelopeHeaderConstants.MESSAGE_TOPIC];

            // guard clause -- make sure we have a topic
            if (null == topic)
            {
                throw new ArgumentException("Cannot route a message with no topic");
            }


            // try to get routing information from the injected info retriever
            routing = _routingRepo.RetrieveRoutingInfo(topic);

            // if we have no routing, ask the fallback provider
            if (routing.IsNullOrEmpty())
            {
                routing = _fallbackProvider.GetFallbackRoute(topic);
            }

            // if even the fallback provider can't help us, we're done
            if (routing.IsNullOrEmpty())
            {
                throw new RoutingInfoNotFoundException("No routing for: " + topic);
            }


            // finally, return the routing
            return(routing);
        }
示例#6
0
        /// <summary>
        /// Used by OutboundTransportManager
        ///
        /// 1. DeQ bunch of messages from OutboundQueue
        /// 2. Transport each of them
        /// 3. RemoveFromQ each of them or suspend them as appropriate
        /// </summary>
        /// <param name="count">Number of messages to DeQ</param>
        /// <returns></returns>
        public List <IOutboundFatpipeMessage> DeQFromOutgoingQ(int count)
        {
            int             iter = 0;
            IFatpipeMessage msg  = null;
            List <IOutboundFatpipeMessage> msgList = new List <IOutboundFatpipeMessage>();

            while (iter < count)
            {
                msg = fpmDal.Dequeue(Constants.QueueType.OUTBOUND);
                if (msg == null)
                {
                    break;
                }

                IOutboundFatpipeMessage message = msg as IOutboundFatpipeMessage;
                string partnerId;
                bool   flag = msg.Header.Context.TryGetValue("PartnerId", out partnerId);
                if (flag)
                {
                    RoutingInfo routingInfo = new RoutingInfo(partnerId, TransportType.None);
                    flag = msg.Header.Context.TryGetValue("TransportType", out partnerId);
                    routingInfo.TransportType = (TransportType)Enum.Parse(typeof(TransportType), partnerId, true);
                    message.RoutingInfo       = routingInfo;
                }

                msgList.Add(message);
                iter++;
            }

            return(msgList);
        }
示例#7
0
        public RoutingSetReq QRFRoutingSet(QuoteRoutingViewModel model, string CurrentUser)
        {
            RoutingSetReq routingSetReq = new RoutingSetReq();

            routingSetReq.QRFID             = model.QRFID;
            routingSetReq.IsOverwriteExtPos = model.IsOverwriteExtPos;
            routingSetReq.IsSetPrefHotels   = model.IsSetPrefHotels;
            routingSetReq.RoutingInfo       = new List <RoutingInfo>();
            model.QuoteRoutingData          = model.QuoteRoutingData.Where(a => !string.IsNullOrEmpty(a.FromCityID) && !string.IsNullOrEmpty(a.ToCityID)).ToList();
            foreach (var objModel in model.QuoteRoutingData)
            {
                var obj = new RoutingInfo();

                obj.RouteSequence  = objModel.RouteSequence;
                obj.RouteID        = objModel.RouteID;
                obj.FromCityID     = objModel.FromCityID;
                obj.ToCityID       = objModel.ToCityID;
                obj.Days           = Convert.ToInt16(objModel.Days);
                obj.Nights         = Convert.ToInt16(objModel.Nights);
                obj.IsLocalGuide   = objModel.IsLocalGuide;
                obj.PrefStarRating = objModel.PrefStarRating;

                obj.CreateUser = CurrentUser;
                obj.CreateDate = DateTime.Now;
                obj.EditUser   = CurrentUser;
                obj.EditDate   = DateTime.Now;

                routingSetReq.RoutingInfo.Add(obj);
            }

            return(routingSetReq);
        }
示例#8
0
 public FatpipeMessage(string tenantIdentifier, string msgId, FatpipeManager fpm)
 {
     _header     = new MessageHeader(tenantIdentifier, msgId);
     _body       = new MessageBody();
     _status     = new MessageStatus();
     this.fpm    = fpm;
     routingInfo = null;
 }
示例#9
0
//HELPERS
    protected override void handleRoutingInfo(RoutingInfo info, NetworkInterface netInt)
    {
        if (info is DijkstraState)
        {
            handleState((DijkstraState)info);
        }
        else if (info is DijkstraUpdate)
        {
            handleUpdate((DijkstraUpdate)info);
        }
    }
示例#10
0
 protected override void handleRoutingInfo(RoutingInfo info, NetworkInterface netInt)
 {
     if (info is AodvRRep)
     {
         handleRouteReply((AodvRRep)info, netInt);
     }
     if (info is AodvRReq)
     {
         handleRouteRequest((AodvRReq)info, netInt);
     }
 }
示例#11
0
        public void Put(String topic, RoutingInfo routingInfo)
        {
            lock (_cacheLock)
            {
                // creating a new cache policy each time is annoying, but necessary
                // see: http://stackoverflow.com/questions/16972641/expiring-a-cached-item-via-cacheitempolicy-in-net-memorycache
                CacheItemPolicy expirationPolicy = new CacheItemPolicy()
                {
                    AbsoluteExpiration = new DateTimeOffset(DateTime.UtcNow.AddSeconds(_cacheExpiryInSeconds))
                };

                _routingInfoCache.Add(new CacheItem(topic, routingInfo), expirationPolicy);
            }
        }
示例#12
0
        public void Register(IRegistration registration)
        {
            Log.Debug("Enter Register");

            // first, get the topology based on the registration info
            RoutingInfo routing = _topologyService.GetRoutingInfo(registration.Info);

            // next, pull out all the producer exchanges
            List <Exchange> exchanges = new List <Exchange>();

            foreach (RouteInfo route in routing.Routes)
            {
                exchanges.Add(route.ConsumerExchange);
            }

            foreach (var exchange in exchanges)
            {
                RabbitListener listener = createListener(registration, exchange);
            }

            Log.Debug("Leave Register");
        }
示例#13
0
        public RoutingInfo GetRoutingFromCacheOrService(
            IRoutingInfoCache cache,
            ITopologyService service,
            IDictionary <string, string> hints)
        {
            // if there are no hints, we have no idea what to do
            if ((null == hints) || (!hints.Any()))
            {
                return(null);
            }

            // pull the topic from the hints
            string topic = hints.GetMessageTopic();

            // first, check the cache
            RoutingInfo routing = cache.GetIfPresent(topic);

            // if nothing, use the service
            if (null == routing)
            {
                Log.Debug(string.Format("No routing information cache for {0}; using the topology service.", topic));

                routing = service.GetRoutingInfo(hints);

                // if we get something from the service, cache it
                if (null != routing)
                {
                    cache.Put(topic, routing);
                }
            }
            else
            {
                Log.Debug(string.Format("Routing information for {0} was found in the cache.", topic));
            }

            // whatever we end up with, return it
            return(routing);
        }
示例#14
0
        public void Register(IRegistration registration)
        {
            Log.Debug("Enter Register");

            // first, get the topology based on the registration info
            RoutingInfo routing = this.GetRoutingFromCacheOrService(_routingInfoCache, _topoSvc, registration.Info);

            // next, pull out all the consumer exchanges
            IEnumerable <Exchange> exchanges =
                from route in routing.Routes
                select route.ConsumerExchange;

            foreach (Exchange ex in exchanges)
            {
                IConnection conn = _connFactory.ConnectTo(ex);

                // create a listener
                RabbitListener listener = new RabbitListener(registration, ex, conn);
                listener.OnEnvelopeReceived += this.listener_OnEnvelopeReceived;
                listener.OnClose            += _listeners.Remove;

                // put it on another thread so as not to block this one but
                // don't continue on this thread until we've started listening
                ManualResetEvent startEvent     = new ManualResetEvent(false);
                Thread           listenerThread = new Thread(listener.Start);
                listenerThread.Name = string.Format("{0} on {1}:{2}{3}", ex.QueueName, ex.HostName, ex.Port, ex.VirtualHost);
                listenerThread.Start(startEvent);

                // wait for the RabbitListener to start
                startEvent.WaitOne(new TimeSpan(0, 0, 30));

                // store the listener
                _listeners.Add(registration, listener);
            }

            Log.Debug("Leave Register");
        }
示例#15
0
        public virtual int GetRoutingInfo(ref RoutingInfo inInfo, ref RoutingInfo outInfo)
        {
            System.Diagnostics.Trace.WriteLine("IComponent.GetRoutingInfo");

            return(TResult.E_NotImplemented);
        }
 public RoutingNameWithActionTokenController(RoutingInfo routingInfo)
 {
     this.routingInfo = routingInfo;
 }
示例#17
0
 public RoutingMandatoryControllerParamController(RoutingInfo routingInfo)
 {
     this.routingInfo = routingInfo;
 }
示例#18
0
 public RoutingVerbsController(RoutingInfo routingInfo)
 {
     this.routingInfo = routingInfo;
 }
 public ModelBindingController(RoutingInfo routingInfo)
 {
     this.routingInfo = routingInfo;
 }
 public RoutingAreaRenamedController(RoutingInfo routingInfo)
 {
     this.routingInfo = routingInfo;
 }
示例#21
0
 public IAsyncResult BeginRoute(Key dest, EndPoint[] firstHops, int numOfCandidates, int numOfSimultaneous, AsyncCallback callback, object state)
 {
     RoutingInfo ri = new RoutingInfo (this, dest, numOfCandidates, numOfSimultaneous, _strict_mode, callback, state);
     ri.Start (firstHops);
     return ri;
 }
示例#22
0
//CONSTRUCTOR
    public RoutingInfoBundle(Node source, Node destination, RoutingInfo routingInfo)
        : base(source, destination, null, Configuration.Protocols.Bundle.LifeTime)
    {
        this.routingInfo = routingInfo;
    }
 public RoutingAreaDefaultController(RoutingInfo routingInfo)
 {
     this.routingInfo = routingInfo;
 }
 public RoutingNamedController(RoutingInfo routingInfo)
 {
     this.routingInfo = routingInfo;
 }
示例#25
0
 protected virtual void handleRoutingInfo(RoutingInfo info, NetworkInterface netInt)
 {
     //default implementation ignores routing info
 }
 public RoutingActionController(RoutingInfo routingInfo)
 {
     this.routingInfo = routingInfo;
 }
 public RoutingRenamingHeaderController(RoutingInfo routingInfo)
 {
     this.routingInfo = routingInfo;
 }
 public RoutingPrefixHeaderController(RoutingInfo routingInfo)
 {
     this.routingInfo = routingInfo;
 }