Пример #1
0
        public override IMessageQueue Create(IMessageQueueConnection connection)
        {
            var azureConnection = (AzureMessageQueueConnection)connection;

            var manager = NamespaceManager.CreateFromConnectionString(azureConnection.Endpoint);

            if (string.IsNullOrWhiteSpace(azureConnection.Subscription))
            {
                if (!manager.QueueExists(azureConnection.Name))
                {
                    manager.CreateQueue(azureConnection.Name);
                }
            }
            else
            {
                if (!manager.TopicExists(azureConnection.Name))
                {
                    manager.CreateTopic(azureConnection.Name);
                }

                if (!manager.SubscriptionExists(azureConnection.Name, azureConnection.Subscription))
                {
                    manager.CreateSubscription(azureConnection.Name, azureConnection.Subscription);
                }
            }

            return(Connect(connection));
        }
Пример #2
0
        public override IMessageQueue Connect(IMessageQueueConnection connection)
        {
            var azureConnection = (AzureMessageQueueConnection)connection;

            _logger.LogInformation($"[Registered] {connection.Id} | {connection.Direction} | {connection.Pattern} | {azureConnection.Endpoint}");
            return(new AzureMessageQueue(azureConnection, this));
        }
Пример #3
0
 public ReceiveMessages(IMessageQueueConnection messageQueueConnection, IMessageQueueProcessing messageProcessor, MessageQueueAppConfig appConfig, ConnectionStrings connectionStrings, List <IMessageQueueConfiguration> messageQueueConfigurations)
 {
     _messageQueueConnection     = messageQueueConnection;
     _messageQueueConfigurations = messageQueueConfigurations;
     _connectionStrings          = connectionStrings;
     _messageProcessor           = messageProcessor;
     _appConfig = appConfig;
 }
Пример #4
0
        /// <summary>
        /// Constructor
        /// </summary>
        /// <param name="exchangeName"></param>
        /// <param name="messageQueueAppConfig"></param>
        /// <param name="messageQueueConnection"></param>
        public MessageQueueConfiguration(string exchangeName, MessageQueueAppConfig messageQueueAppConfig, IMessageQueueConnection messageQueueConnection)
        {
            TransactionCode = exchangeName;

            _messageQueueAppConfig  = messageQueueAppConfig;
            _messageQueueConnection = messageQueueConnection;
            _exchangeName           = exchangeName;
            _boundedQueues          = new List <string>();
        }
Пример #5
0
 /// <summary>
 /// Send Messages
 /// </summary>
 /// <param name="messageQueueConnection"></param>
 /// <param name="messageProcessor"></param>
 /// <param name="appConfig"></param>
 /// <param name="connectionStrings"></param>
 /// <param name="messageQueueConfigurations"></param>
 public SendMessages(IMessageQueueConnection messageQueueConnection, IMessageQueueProcessing messageProcessor, MessageQueueAppConfig appConfig, ConnectionStrings connectionStrings, List <IMessageQueueConfiguration> messageQueueConfigurations, string signalRQueue)
 {
     _messageQueueConnection     = messageQueueConnection;
     _messageQueueConfigurations = messageQueueConfigurations;
     _connectionStrings          = connectionStrings;
     _messageProcessor           = messageProcessor;
     _appConfig    = appConfig;
     _signalRQueue = signalRQueue;
 }
Пример #6
0
        /// <summary>
        /// 关闭
        /// </summary>
        public static void Close()
        {
            if (connection != null && connection.Status == ConnectionStatusType.OPENED)
            {
                connection.Close();
            }

            connection = null;
        }
Пример #7
0
        private readonly List <RunningCrawler> runningCrawlers = new List <RunningCrawler>(); //Buscar do banco caso morra

        public Worker(ILogger <Worker> logger, IMessageQueueConnection mq, IDatabase db)
        {
            _logger = logger;
            _mq     = mq;
            _db     = db;

            _mq.CreateQueue(MqHelper.OrchestratorQueueName());
            _mq.ConfigureConsumeQueueListener(MqHelper.OrchestratorQueueName(), true, CreateCrawler);
        }
Пример #8
0
        static void Main(string[] args)
        {
            mq = Injection.GetService <IMessageQueueConnection>();

            bot.OnMessage += Bot_OnMessage;

            bot.StartReceiving();

            while (true)
            {
            }
        }
        /// <summary>
        /// 设置消息队列读取
        /// </summary>
        /// <param name="conn">消息队列连接</param>
        /// <param name="reader">消息队列读取</param>
        public static void SetMessageQueueReader(this IMessageQueueConnection conn, IRabbitMessageQueueReader reader)
        {
            if (conn == null)
            {
                return;
            }

            RabbitConnection rabbitConn = null;

            if (conn is RabbitAutoRecoveryConnection)
            {
                var autoRabbitConn = conn as RabbitAutoRecoveryConnection;
                if (autoRabbitConn.ProtoConnection == null)
                {
                    autoRabbitConn.ProtoConnection = new RabbitConnection();
                }
                else if (autoRabbitConn.ProtoConnection is RabbitConnection)
                {
                    rabbitConn = autoRabbitConn.ProtoConnection as RabbitConnection;
                }
                else
                {
                    throw new NotSupportedException("RabbitAutoRecoveryConnection.ProtoConnection不是RabbitConnection");
                }
            }
            else if (conn is RabbitConnection)
            {
                rabbitConn = conn as RabbitConnection;
            }
            else
            {
                throw new NotSupportedException("不支持的连接类型,必须是RabbitConnection");
            }

            RabbitMessageQueueInfoConfigFactory msgQueueConfigFactoy = null;

            if (rabbitConn.MessageQueueInfoFactory == null)
            {
                msgQueueConfigFactoy = new RabbitMessageQueueInfoConfigFactory();
                rabbitConn.MessageQueueInfoFactory = msgQueueConfigFactoy;
            }
            else if (rabbitConn.MessageQueueInfoFactory is RabbitMessageQueueInfoConfigFactory)
            {
                msgQueueConfigFactoy = rabbitConn.MessageQueueInfoFactory as RabbitMessageQueueInfoConfigFactory;
            }
            else
            {
                throw new NotSupportedException("消息队列信息工厂不支持的类型,必须是RabbitMessageQueueInfoConfigFactory");
            }

            msgQueueConfigFactoy.MessageQueueReader = reader;
        }
        /// <summary>
        /// Send Messages
        /// </summary>
        /// <param name="messageQueueConnection"></param>
        /// <param name="messageProcessor"></param>
        /// <param name="appConfig"></param>
        /// <param name="connectionStrings"></param>
        /// <param name="messageQueueConfigurations"></param>
        public SendMessages(IMessageQueueConnection messageQueueConnection, IMessageQueueProcessing messageProcessor, MessageQueueAppConfig appConfig, ConnectionStrings connectionStrings, List <IMessageQueueConfiguration> messageQueueConfigurations, string signalRQueue)
        {
            _messageQueueConnection     = messageQueueConnection;
            _messageQueueConfigurations = messageQueueConfigurations;
            _connectionStrings          = connectionStrings;
            _messageProcessor           = messageProcessor;
            _appConfig    = appConfig;
            _signalRQueue = signalRQueue;

            using (var sw = File.AppendText(Path))
            {
                sw.WriteLine("Send Messages Constructor");
            }
        }
Пример #11
0
        protected static void StartConsumer(string queueName)
        {
            using (_messageQueueConnection = IoC.GetService <IMessageQueueConnection>())
            {
                _messageQueueConnection.ReceivedMessage += ReceivedMessage;

                _messageQueueConnection.ListenToQueue(queueName, null);

                while (true)
                {
                    System.Threading.Thread.Sleep(300);
                }
            }
        }
Пример #12
0
        /// <summary>
        /// 调用
        /// </summary>
        /// <param name="method">方法</param>
        /// <param name="message">消息</param>
        /// <returns>返回数据</returns>
        public object Call(MethodInfo method, object message)
        {
            var assemblyName = method.DeclaringType.Assembly.GetName().Name;
            var configInfo   = rabbitConfigReader.Reader();

            if (configInfo == null)
            {
                throw new Exception("找不到RabbitConfig配置信息");
            }

            RpcClientAssemblyWrapInfo rpcClientAssemblyWrap;
            var messQueueInfo = GetMessageQueueByAssemblyName(configInfo, assemblyName, out rpcClientAssemblyWrap);

            if (rpcClientAssemblyWrap == null)
            {
                throw new Exception($"找不到程序集[{assemblyName}]的RPC客户端配置信息");
            }

            var byteSeri = GetByteSerialization(rpcClientAssemblyWrap.RpcClientAssembly.DataType);
            var byteData = byteSeri.Serialize(message);

            IRpcClient rpcClient = null;

            if (dicVirtualPathMapRpcClient.ContainsKey(rpcClientAssemblyWrap.RabbitVirtualPath.VirtualPath))
            {
                rpcClient = dicVirtualPathMapRpcClient[rpcClientAssemblyWrap.RabbitVirtualPath.VirtualPath];
            }
            else
            {
                lock (syncDicVirtualPathMapRpcClient)
                {
                    IMessageQueueConnection conn = null;
                    // 如果连接配置信息不全,则找默认的连接对象
                    if (string.IsNullOrWhiteSpace(rpcClientAssemblyWrap.RabbitVirtualPath.ConnectionString) && string.IsNullOrWhiteSpace(rpcClientAssemblyWrap.RabbitVirtualPath.ConnectionStringAppConfigName))
                    {
                        conn = SingleConnectionTool.CreateConnection();
                    }
                    else
                    {
                        conn = connectionFactoy.CreateAndOpen(new ConnectionWrapInfo()
                        {
                            ConnectionString = rpcClientAssemblyWrap.RabbitVirtualPath.ConnectionString,
                            ConnectionStringAppConfigName = rpcClientAssemblyWrap.RabbitVirtualPath.ConnectionStringAppConfigName
                        });
                    }
                    connections.Add(conn);

                    rpcClient = conn.CreateRpcClient(messQueueInfo);
                    try
                    {
                        dicVirtualPathMapRpcClient.Add(rpcClientAssemblyWrap.RabbitVirtualPath.VirtualPath, rpcClient);
                    }
                    catch (ArgumentException) { }
                }
            }

            var reData = rpcClient.Call(byteData);

            // 如果返回值是空或者类型是void,则直接返回null
            if (reData.IsNullOrLength0() || method.ReturnType.IsTypeVoid())
            {
                return(null);
            }
            else
            {
                Type targetType = null;

                // 判断返回类型是否Task
                if (method.ReturnType.IsTypeNotGenericityTask())
                {
                    return(null);
                }
                else if (method.ReturnType.IsTypeGenericityTask())
                {
                    targetType = method.ReturnType.GetProperty("Result").PropertyType;
                }
                else
                {
                    targetType = method.ReturnType;
                }

                return(byteSeri.Deserialize(reData, targetType));
            }
        }
 public MessageQueueBase(IMessageQueueConnection connection, IMessageQueueFactory queueFactory)
 {
     Connection   = connection;
     QueueFactory = queueFactory;
 }
 public MsmqMessageQueue(IMessageQueueConnection connection, IMessageQueueFactory queueFactory)
     : base(connection, queueFactory)
 {
     Queue = new MessageQueue(connection.Address);
 }
Пример #15
0
 public WeatherForecastController(ILogger <WeatherForecastController> logger, IMessageQueueConnection conn, IMessageQueueConnectionFactory factory)
 {
     _logger      = logger;
     this.conn    = conn;
     this.factory = factory;
 }
Пример #16
0
 public Scheduler(IDatabase database, IMessageQueueConnection mq)
 {
     _database = database;
     _mq       = mq;
 }
Пример #17
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="messageQueueAppConfig"></param>
 /// <param name="messageQueueConnection"></param>
 public MessageQueueConfiguration(MessageQueueAppConfig messageQueueAppConfig, IMessageQueueConnection messageQueueConnection)
 {
     _messageQueueAppConfig  = messageQueueAppConfig;
     _messageQueueConnection = messageQueueConnection;
 }
Пример #18
0
 public GetSheet(IMessageQueueConnection mqConnection,
                 IDatabase database)
 {
     _mqConnection = mqConnection;
     _database     = database;
 }
 public abstract IMessageQueue Create(IMessageQueueConnection connection);
Пример #20
0
 public static void ReceivedMessage(IMessageQueueConnection connection, ReceivedMessageEventArgs e)
 {
     _logger.LogInformation($"Mensagem recebida -> {e.Message}");
 }
 public ZeroMqMessageQueue(NetMQContext context, IMessageQueueConnection connection, IMessageQueueFactory queueFactory)
     : base(connection, queueFactory)
 {
     Queue = Connection.Direction == Direction.Inbound ? GetInboundSocket(context) : GetOutboundSocket(context);
 }