Exemplo n.º 1
0
        static void ClientLoop(object state)
        {
            var addr   = (ITransfer)state;
            var client = new RabbitBroker();

            client.Open();
            Thread.Sleep(3 * 1000);
            client.Publish(addr, $"Hello, I am a client ({addr})");
        }
Exemplo n.º 2
0
        public void Start()
        {
            Handlers = new Dictionary <Type, IRequestHandler>();
            log.InfoFormat("Service is starting...");
            var name   = GetType().Name;
            var client = new RabbitBroker();

            client.Open();
            Client = client;
            log.InfoFormat("Service is started!");
            var id = client.Id;

            client.Publish(id.Broad, new HelloMessage
            {
                Machine = Environment.MachineName,
                User    = Environment.UserName,
                Local   = client.LocalEndpoint.ToShortString(),
                Remote  = client.RemoteEndpoint.ToShortString()
            });
            foreach (var pair in AddinExtensions.GetFiltered <ReqHandlerFilterAttribute, IRequestHandler>())
            {
                var handler  = pair.Value;
                var intfName = typeof(IRequestHandler <>).Name;
                foreach (var intf in handler.GetType().GetInterfaces())
                {
                    if (!(intf.Name.Equals(intfName)))
                    {
                        continue;
                    }
                    var reqType = intf.GetGenericArguments()[0];
                    GetType().GenericMe(nameof(Subscribe), reqType).Invoke(this, null);
                    log.InfoFormat("Found '{0}' for '{1}'.", handler, reqType);
                    Handlers[reqType] = handler;
                }
            }
        }