Пример #1
0
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="configuration">Configuration</param>
 /// <param name="logger">Logger</param>
 public RabbitPublisher(RabbitPublisherConfiguration configuration, ILogger logger = null)
     : base(configuration, logger)
 {
     // ...
     Configuration = configuration;
     // Declaring publish properties.
     PublishProperties         = Channel.CreateBasicProperties();
     PublishProperties.Headers = new Dictionary <string, object> {
     };
     // Persistent means, that message will be saved on hard disk
     // So it will never dissapear until deleted purposely
     PublishProperties.Persistent = true;
     // Defining the destination
     Destination = Configuration.Exchange ? Configuration.Name : string.Empty;
     // Defining the routes
     Routes = configuration.Dependencies
              .Select(dependency => dependency.Route)
              .Where(route => !string.IsNullOrWhiteSpace(route))
              .ToList();
     if (Routes.Count == 0)
     {
         Routes.Add(configuration.Name);
     }
     DefaultRoute = Routes.Count == 1 ? Routes[0] : string.Empty;
     // On start event
     OnStart();
 }
Пример #2
0
        /// <summary>
        /// Publisher constructor
        /// </summary>
        /// <param name="configuration">Publisher configuration</param>
        /// <param name="logger">Logger</param>
        internal RabbitBase(RabbitPublisherConfiguration configuration, ILogger logger = null)
            : this((RabbitConfigurationBase)configuration, logger)
        {
            // Validations
            if (configuration.Exchange)
            {
                if (!AllowedExchangeTypes.Contains(configuration.Type))
                {
                    throw new NotImplementedException(string.Format(RabbitAnnotations.Exception.FactoryNotImplementedExceptionPublisher, configuration.Type));
                }
            }
            // Declaring channel
            var channel = DeclareChannel(configuration);

            // Declaring exchange
            if (configuration.Exchange)
            {
                DeclareExchange(channel, configuration.Name, configuration.Type, Arguments);
                foreach (var dependency in configuration.Dependencies)
                {
                    if (string.IsNullOrWhiteSpace(dependency.Route) || string.IsNullOrWhiteSpace(dependency.Name))
                    {
                        continue;
                    }
                    DeclareQueue(channel, dependency.Name, new Dictionary <string, string> {
                        { configuration.Name, dependency.Route }
                    });
                }
            }
            // Declaring queue
            else
            {
                DeclareQueue(channel, configuration.Name, null);
            }
            // Register channel
            Channels.Add(channel);
        }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="configuration">Configuration</param>
 public DeadPublisher(RabbitPublisherConfiguration configuration) : base(configuration)
 {
 }
 /// <summary>
 /// Constructor
 /// </summary>
 /// <param name="configuration">Configuration</param>
 public RetryPublisher(RabbitPublisherConfiguration configuration) : base(configuration)
 {
 }