public static RabbitContext Create(this RabbitContext ctx, string fileName)
        {
            ctx = new RabbitContext();

            var    filePath     = Path.Combine(@"Configuration", fileName);
            string fullFilePath = Path.Combine(AppDomain.CurrentDomain.BaseDirectory, filePath);
            string json         = File.ReadAllText(fullFilePath);

            ctx = JsonConvert.DeserializeObject <RabbitContext>(json);

            return(ctx);
        }
        public static RabbitContext Create(this RabbitContext ctx, string exchange, string exchangeType, string routingKey = "")
        {
            ctx = new RabbitContext();

            ctx.Connection = new RabbitConnection();
            ctx.Connection.ClearDefaults();
            ctx.Connection.HostName = "localhost";
            ctx.Exchange.Name       = exchange;
            ctx.Exchange.Type       = exchangeType;
            ctx.Binder.ExchangeName = exchange;
            ctx.Binder.RoutingKey   = routingKey;
            return(ctx);
        }
        public void Create(string connectionName, string exchangeName, string queueName, string routingKey)
        {
            Context = new RMQContext().Create(ConfigFileName);

            RabbitContext = new RabbitContext();

            RabbitContext.Connection = Context.Connections.Where(r => r.Name == connectionName).FirstOrDefault();
            RabbitContext.Exchange   = Context.Exchanges.Where(r => r.Name == exchangeName).FirstOrDefault();
            RabbitContext.Queue      = Context.Queues.Where(r => r.Name == queueName).FirstOrDefault();
            RabbitContext.Binder     = new RabbitBinder()
            {
                ExchangeName = RabbitContext.Exchange.Name,
                QueueName    = RabbitContext.Queue.Name,
                RoutingKey   = routingKey
            };

            Sender = new RmqSender(RabbitContext);
            Sender.SetRoutingKey(RabbitContext.Queue.Name, RabbitContext.Binder.RoutingKey);

            // Receiver = new RMQReceiver(_ctx);
        }
        public RMQReceiver(RabbitContext ctx)
        {
            this.ctx = ctx;

            try
            {
                var factory = new ConnectionFactory()
                {
                    VirtualHost = ctx.Connection.VirtualHost,
                    HostName    = ctx.Connection.HostName,
                    UserName    = ctx.Connection.UserName,
                    Password    = ctx.Connection.Password
                };

                this.connection = Connection.Connect(this.ctx);
                this.channel    = connection.CreateModel();
            }
            catch (Exception ex)
            {
                Console.WriteLine("RabbitListener init error ex:{0}", ex.Message);
                throw ex;
            }
        }
Exemple #5
0
        public static IConnection Connect(RabbitContext ctx)
        {
            RabbitConnection  options = ctx.Connection;
            ConnectionFactory factory = new ConnectionFactory();

            if (!string.IsNullOrWhiteSpace(options.UserName))
            {
                factory.UserName = options.UserName;
            }
            if (!string.IsNullOrWhiteSpace(options.Password))
            {
                factory.Password = options.Password;
            }
            if (!string.IsNullOrWhiteSpace(options.UserName))
            {
                factory.VirtualHost = options.VirtualHost;
            }

            factory.HostName = options.HostName;
            IConnection conn = factory.CreateConnection();

            return(conn);
        }
 public RmqSender(RabbitContext ctx)
 {
     this.ctx = ctx;
 }
 public SenderNew(RabbitContext ctx)
 {
     this.ctx = ctx;
 }