public string SelectTopic(IRemoteEventData eventData) { if (eventData is IHasTopicRemoteEventData) { return((eventData as IHasTopicRemoteEventData).Topic); } foreach (var item in _mapping) { if (item.Key.IsAssignableFrom(eventData.GetType())) { return(item.Value); } } return(TOPIC_DEFAULT); }
public void Publish(IRemoteEventData remoteEventData) { var routingKey = remoteEventData.GetType().FullName; var connection = _connectionPool.Acquire(); try { var channel = connection.CreateModel(); channel.ExchangeDeclare(_rabbitMqEventBusOptions.ExchangeName, "direct", true); var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(remoteEventData)); var properties = channel.CreateBasicProperties(); properties.Persistent = true; channel.BasicPublish(_rabbitMqEventBusOptions.ExchangeName, routingKey, properties, body); } finally { _connectionPool.Return(connection); } }