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)); }
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)); }
public ReceiveMessages(IMessageQueueConnection messageQueueConnection, IMessageQueueProcessing messageProcessor, MessageQueueAppConfig appConfig, ConnectionStrings connectionStrings, List <IMessageQueueConfiguration> messageQueueConfigurations) { _messageQueueConnection = messageQueueConnection; _messageQueueConfigurations = messageQueueConfigurations; _connectionStrings = connectionStrings; _messageProcessor = messageProcessor; _appConfig = appConfig; }
/// <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>(); }
/// <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; }
/// <summary> /// 关闭 /// </summary> public static void Close() { if (connection != null && connection.Status == ConnectionStatusType.OPENED) { connection.Close(); } connection = null; }
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); }
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"); } }
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); } } }
/// <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); }
public WeatherForecastController(ILogger <WeatherForecastController> logger, IMessageQueueConnection conn, IMessageQueueConnectionFactory factory) { _logger = logger; this.conn = conn; this.factory = factory; }
public Scheduler(IDatabase database, IMessageQueueConnection mq) { _database = database; _mq = mq; }
/// <summary> /// /// </summary> /// <param name="messageQueueAppConfig"></param> /// <param name="messageQueueConnection"></param> public MessageQueueConfiguration(MessageQueueAppConfig messageQueueAppConfig, IMessageQueueConnection messageQueueConnection) { _messageQueueAppConfig = messageQueueAppConfig; _messageQueueConnection = messageQueueConnection; }
public GetSheet(IMessageQueueConnection mqConnection, IDatabase database) { _mqConnection = mqConnection; _database = database; }
public abstract IMessageQueue Create(IMessageQueueConnection connection);
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); }