Ejemplo n.º 1
0
 public void Add(Type type, IMessageConvention convention)
 {
     if (_conventions.ContainsKey(type))
     {
         _conventions[type] = convention;
     }
     else
     {
         _conventions.Add(type, convention);
     }
 }
Ejemplo n.º 2
0
        public void Send(
            object message,
            IMessageConvention convention,
            string messageId     = null,
            string correlationId = null,
            string spanContext   = null,
            IDictionary <string, object> headers = null)
        {
            if (message is null)
            {
                if (_isLoggerEnabled)
                {
                    _logger.LogWarning("Cannot null message via convention: {Convention}", convention);
                }
                return;
            }

            var threadId = Thread.CurrentThread.ManagedThreadId;

            if (!_channels.TryGetValue(threadId, out var channel))
            {
                if (_channelsCount >= _maxChannels)
                {
                    throw new InvalidOperationException(
                              $"Cannot create new channel, limit reached. Got {_channelsCount} of {_maxChannels} possible");
                }

                channel = _connection.CreateModel();
                _channels.TryAdd(threadId, channel);
                Interlocked.Increment(ref _channelsCount);
                _logger.LogTrace(
                    $"Created a channel for thread: {threadId}, total channels: {_channelsCount}/{_maxChannels}");
            }

            var messageBody  = _serializer.SerializeBinary(message);
            var channelProps = GetBasicProperties(channel, messageId, correlationId, spanContext, headers);

            channel.BasicPublish(convention.Exchange, convention.Route, channelProps, messageBody);
        }
Ejemplo n.º 3
0
 internal void Add(IMessageConvention messageConvention)
 {
     conventions.Add(messageConvention);
 }
Ejemplo n.º 4
0
 public void Add <T>(IMessageConvention convention)
 => Add(typeof(T), convention);
Ejemplo n.º 5
0
        public static void Add(this Conventions conventions, IMessageConvention convention)
        {
            var addMethod = typeof(Conventions).GetMethod("Add", BindingFlags.Instance | BindingFlags.NonPublic);

            addMethod.Invoke(conventions, new object[] { convention });
        }
 public OverridableMessageConvention(IMessageConvention inner)
 {
     this.inner = inner;
 }
Ejemplo n.º 7
0
 /// <summary>
 /// Adds a message convention that will be used to evaluate whether a type is a message, command, or event.
 /// </summary>
 public ConventionsBuilder Add(IMessageConvention messageConvention)
 {
     Guard.AgainstNull(nameof(messageConvention), messageConvention);
     Conventions.Add(messageConvention);
     return(this);
 }