示例#1
0
 /// <summary>
 /// 注销指定的服务
 /// </summary>
 /// <param name="reg"></param>
 public static void Dispose(RegisterServer <T> reg)
 {
     try
     {
         reg.Unregister(typeof(T).Name);
     }
     catch (Exception e)
     {
         Logs.Create("停止消息服务失败:" + e.Message);
     }
 }
示例#2
0
        /// <summary>
        /// 私人消息队列
        /// </summary>
        public MessageQueueEvent()
        {
            BroadcastEvent be = new BroadcastEvent();

            reg = MessageServer <BroadcastEvent> .Intialize(be, ConfigurationManager.AppSettings["service"], Convert.ToInt32(ConfigurationManager.AppSettings["port"]));

            if (reg.Channels.Count > 0)
            {
                this.channel = reg.Channels[0];//.Find(a => a.ChannelName == ConfigurationManager.AppSettings["service"]);
            }
            be.Channel = this.channel;
            if (reg.Uris.Count > 0)
            {
                this.uri = reg.Uris.Find(a => a.Segments[a.Segments.Length - 1] == ConfigurationManager.AppSettings["service"]);
            }
        }
示例#3
0
        /// <summary>
        /// 私人消息队列
        /// </summary>
        public ClonableMessageTrunkQuery()
        {
            trunk = new KellPersistence.Trunk <ClonableObject>("KellMQ.ClonableObject");
            messageNotifyEvent  = new Dictionary <Guid, ClonableConsumeEventHandler>();
            messagesNotifyEvent = new Dictionary <Guid, ClonableConsumingEventHandler>();
            BroadcastEvent be = new BroadcastEvent();

            reg = MessageServer <BroadcastEvent> .Intialize(be, ConfigurationManager.AppSettings["service2"], Convert.ToInt32(ConfigurationManager.AppSettings["port2"]));

            if (reg.Channels.Count > 0)
            {
                this.channel = reg.Channels[0];//.Find(a => a.ChannelName == ConfigurationManager.AppSettings["service2"]);
            }
            be.Channel = this.channel;
            if (reg.Uris.Count > 0)
            {
                this.uri = reg.Uris.Find(a => a.Segments[a.Segments.Length - 1] == ConfigurationManager.AppSettings["service2"]);
            }
        }
示例#4
0
        /// <summary>
        /// 根据指定的配置文档(ServerCfg.config)启动TCP服务,找不到该配置文件就找app.config
        /// </summary>
        /// <param name="msg"></param>
        public static RegisterServer <T> Init(T msg)
        {
            RegisterServer <T> reg = new RegisterServer <T>();

            try
            {
                if (File.Exists("ServerCfg.config"))
                {
                    RemotingConfiguration.Configure("ServerCfg.config", false);
                }
                else
                {
                    RemotingConfiguration.Configure(AppDomain.CurrentDomain.SetupInformation.ConfigurationFile, false);
                }
                WellKnownServiceTypeEntry swte = new WellKnownServiceTypeEntry(typeof(T), typeof(T).Name, WellKnownObjectMode.Singleton);
                RemotingConfiguration.ApplicationName = typeof(T).Name;
                RemotingConfiguration.RegisterWellKnownServiceType(swte);
                reg.Register(msg);
                IChannel   ch  = ChannelServices.GetChannel(RemotingConfiguration.ApplicationName);
                TcpChannel tch = ch as TcpChannel;
                if (tch != null)
                {
                    if (!reg.Channels.Contains(tch))
                    {
                        reg.Channels.Add(tch);
                    }
                    string[] ss = tch.GetUrlsForUri(swte.ObjectUri);
                    foreach (string uri in ss)
                    {
                        if (!reg.Uris.Exists(a => a.AbsoluteUri == uri))
                        {
                            reg.Uris.Add(new Uri(uri, UriKind.RelativeOrAbsolute));
                        }
                    }
                }
                return(reg);
            }
            catch (Exception e)
            {
                Logs.Create("启动消息服务失败:" + e.Message);
            }
            return(reg);
        }
示例#5
0
        /// <summary>
        /// 根据默认的配置文档(app.config)启动TCP服务
        /// </summary>
        /// <param name="msg"></param>
        /// <param name="port"></param>
        public static RegisterServer <T> Intialize(T msg, string serviceName, int port = 8888)
        {
            RegisterServer <T> reg = new RegisterServer <T>();

            try
            {
                BinaryServerFormatterSinkProvider serverProv = new BinaryServerFormatterSinkProvider();
                serverProv.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
                //BinaryClientFormatterSinkProvider clientProv = new BinaryClientFormatterSinkProvider();
                //IDictionary props = new Hashtable();
                //props["port"] = port;
                TcpServerChannel servChannel = new TcpServerChannel(serviceName, port, serverProv);
                ChannelServices.RegisterChannel(servChannel, false);
                if (!reg.Channels.Contains(servChannel))
                {
                    reg.Channels.Add(servChannel);
                }
                WellKnownServiceTypeEntry swte = new WellKnownServiceTypeEntry(typeof(T), serviceName, WellKnownObjectMode.Singleton);
                //RemotingConfiguration.ApplicationName = serviceName;
                RemotingConfiguration.RegisterWellKnownServiceType(swte);
                reg.Register(msg, serviceName);
                string[] ss = servChannel.GetUrlsForUri(serviceName);
                foreach (string uri in ss)
                {
                    if (!reg.Uris.Exists(a => a.AbsoluteUri == uri))
                    {
                        reg.Uris.Add(new Uri(uri, UriKind.RelativeOrAbsolute));
                    }
                }
                return(reg);
            }
            catch (Exception e)
            {
                Logs.Create("启动服务时出错:" + e.Message);
            }
            return(reg);
        }
示例#6
0
        /// <summary>
        /// 私人消息队列
        /// </summary>
        public MessageQueueQuery()
        {
            messageNotifyEvent  = new Dictionary <Guid, ConsumeEventHandler>();
            messagesNotifyEvent = new Dictionary <Guid, ConsumingEventHandler>();
            List <BaseMessage> oldMsgs = GetAllMessages();

            foreach (BaseMessage msg in oldMsgs)
            {
                this.Add(msg.ID, msg);
            }
            BroadcastEvent be = new BroadcastEvent();

            reg = MessageServer <BroadcastEvent> .Intialize(be, ConfigurationManager.AppSettings["service2"], Convert.ToInt32(ConfigurationManager.AppSettings["port2"]));

            if (reg.Channels.Count > 0)
            {
                this.channel = reg.Channels[0];//.Find(a => a.ChannelName == ConfigurationManager.AppSettings["service2"]);
            }
            be.Channel = this.channel;
            if (reg.Uris.Count > 0)
            {
                this.uri = reg.Uris.Find(a => a.Segments[a.Segments.Length - 1] == ConfigurationManager.AppSettings["service2"]);
            }
        }