/// <summary> /// Initializes a new instance of the <see cref="AmqpProducer"/> class. /// </summary> /// /// <param name="eventHubName">The name of the Event Hub to which events will be published.</param> /// <param name="partitionId">The identifier of the Event Hub partition to which it is bound; if unbound, <c>null</c>.</param> /// <param name="connectionScope">The AMQP connection context for operations.</param> /// <param name="messageConverter">The converter to use for translating between AMQP messages and client types.</param> /// <param name="retryPolicy">The retry policy to consider when an operation fails.</param> /// <param name="requestedFeatures">The flags specifying the set of special transport features that should be opted-into.</param> /// <param name="partitionOptions">The set of options, if any, that should be considered when initializing the producer.</param> /// /// <remarks> /// As an internal type, this class performs only basic sanity checks against its arguments. It /// is assumed that callers are trusted and have performed deep validation. /// /// Any parameters passed are assumed to be owned by this instance and safe to mutate or dispose; /// creation of clones or otherwise protecting the parameters is assumed to be the purview of the /// caller. /// </remarks> /// public AmqpProducer(string eventHubName, string partitionId, AmqpConnectionScope connectionScope, AmqpMessageConverter messageConverter, EventHubsRetryPolicy retryPolicy, TransportProducerFeatures requestedFeatures = TransportProducerFeatures.None, PartitionPublishingOptions partitionOptions = null) { Argument.AssertNotNullOrEmpty(eventHubName, nameof(eventHubName)); Argument.AssertNotNull(connectionScope, nameof(connectionScope)); Argument.AssertNotNull(messageConverter, nameof(messageConverter)); Argument.AssertNotNull(retryPolicy, nameof(retryPolicy)); EventHubName = eventHubName; PartitionId = partitionId; RetryPolicy = retryPolicy; ConnectionScope = connectionScope; MessageConverter = messageConverter; ActiveFeatures = requestedFeatures; ActiveOptions = partitionOptions?.Clone() ?? new PartitionPublishingOptions(); SendLink = new FaultTolerantAmqpObject <SendingAmqpLink>( timeout => CreateLinkAndEnsureProducerStateAsync(partitionId, ActiveOptions, timeout, CancellationToken.None), link => { link.Session?.SafeClose(); link.SafeClose(); }); }
/// <summary> /// Creates a producer strongly aligned with the active protocol and transport, /// responsible for publishing <see cref="EventData" /> to the Event Hub. /// </summary> /// /// <param name="partitionId">The identifier of the partition to which the transport producer should be bound; if <c>null</c>, the producer is unbound.</param> /// <param name="requestedFeatures">The flags specifying the set of special transport features that should be opted-into.</param> /// <param name="partitionOptions">The set of options, if any, that should be considered when initializing the producer.</param> /// <param name="retryPolicy">The policy which governs retry behavior and try timeouts.</param> /// /// <returns>A <see cref="TransportProducer"/> configured in the requested manner.</returns> /// internal virtual TransportProducer CreateTransportProducer(string partitionId, TransportProducerFeatures requestedFeatures, PartitionPublishingOptions partitionOptions, EventHubsRetryPolicy retryPolicy) { Argument.AssertNotNull(retryPolicy, nameof(retryPolicy)); return(InnerClient.CreateProducer(partitionId, requestedFeatures, partitionOptions, retryPolicy)); }
/// <summary> /// Creates a producer strongly aligned with the active protocol and transport, /// responsible for publishing <see cref="EventData" /> to the Event Hub. /// </summary> /// /// <param name="partitionId">The identifier of the partition to which the transport producer should be bound; if <c>null</c>, the producer is unbound.</param> /// <param name="requestedFeatures">The flags specifying the set of special transport features that should be opted-into.</param> /// <param name="partitionOptions">The set of options, if any, that should be considered when initializing the producer.</param> /// <param name="retryPolicy">The policy which governs retry behavior and try timeouts.</param> /// /// <returns>A <see cref="TransportProducer"/> configured in the requested manner.</returns> /// public override TransportProducer CreateProducer(string partitionId, TransportProducerFeatures requestedFeatures, PartitionPublishingOptions partitionOptions, EventHubsRetryPolicy retryPolicy) { Argument.AssertNotClosed(_closed, nameof(AmqpClient)); return(new AmqpProducer ( EventHubName, partitionId, ConnectionScope, MessageConverter, retryPolicy, requestedFeatures, partitionOptions )); }
/// <summary> /// Initializes a new instance of the <see cref="AmqpEventBatch"/> class. /// </summary> /// /// <param name="messageConverter">The converter to use for translating <see cref="EventData" /> into the corresponding AMQP message.</param> /// <param name="options">The set of options to apply to the batch.</param> /// <param name="activeFeatures">The flags specifying the set of special transport features have been opted-into.</param> /// public AmqpEventBatch(AmqpMessageConverter messageConverter, CreateBatchOptions options, TransportProducerFeatures activeFeatures) { Argument.AssertNotNull(messageConverter, nameof(messageConverter)); Argument.AssertNotNull(options, nameof(options)); Argument.AssertNotNull(options.MaximumSizeInBytes, nameof(options.MaximumSizeInBytes)); MessageConverter = messageConverter; Options = options; MaximumSizeInBytes = options.MaximumSizeInBytes.Value; ActiveFeatures = activeFeatures; // Initialize the size by reserving space for the batch envelope. using AmqpMessage envelope = messageConverter.CreateBatchFromEvents(Enumerable.Empty <EventData>(), options.PartitionKey); ReservedSize = envelope.SerializedMessageSize; _sizeBytes = ReservedSize; }
/// <summary> /// Initializes a new instance of the <see cref="AmqpEventBatch"/> class. /// </summary> /// /// <param name="messageConverter">The converter to use for translating <see cref="EventData" /> into the corresponding AMQP message.</param> /// <param name="options">The set of options to apply to the batch.</param> /// <param name="activeFeatures">The flags specifying the set of special transport features have been opted-into.</param> /// public AmqpEventBatch(AmqpMessageConverter messageConverter, CreateBatchOptions options, TransportProducerFeatures activeFeatures) { Argument.AssertNotNull(messageConverter, nameof(messageConverter)); Argument.AssertNotNull(options, nameof(options)); Argument.AssertNotNull(options.MaximumSizeInBytes, nameof(options.MaximumSizeInBytes)); MessageConverter = messageConverter; Options = options; MaximumSizeInBytes = options.MaximumSizeInBytes.Value; ActiveFeatures = activeFeatures; // Initialize the size by reserving space for the batch envelope. At this point, the // set of batch events is empty, so the message returned will only represent the envelope. using AmqpMessage envelope = messageConverter.CreateBatchFromEvents(BatchEvents, options.PartitionKey); ReservedSize = envelope.SerializedMessageSize; _sizeBytes = ReservedSize; }
/// <summary> /// Initializes a new instance of the <see cref="AmqpProducer"/> class. /// </summary> /// /// <param name="eventHubName">The name of the Event Hub to which events will be published.</param> /// <param name="partitionId">The identifier of the Event Hub partition to which it is bound; if unbound, <c>null</c>.</param> /// <param name="producerIdentifier">The identifier to associate with the consumer; if <c>null</c> or <see cref="string.Empty" />, a random identifier will be generated.</param> /// <param name="connectionScope">The AMQP connection context for operations.</param> /// <param name="messageConverter">The converter to use for translating between AMQP messages and client types.</param> /// <param name="retryPolicy">The retry policy to consider when an operation fails.</param> /// <param name="requestedFeatures">The flags specifying the set of special transport features that should be opted-into.</param> /// <param name="partitionOptions">The set of options, if any, that should be considered when initializing the producer.</param> /// /// <remarks> /// As an internal type, this class performs only basic sanity checks against its arguments. It /// is assumed that callers are trusted and have performed deep validation. /// /// Any parameters passed are assumed to be owned by this instance and safe to mutate or dispose; /// creation of clones or otherwise protecting the parameters is assumed to be the purview of the /// caller. /// </remarks> /// public AmqpProducer(string eventHubName, string partitionId, string producerIdentifier, AmqpConnectionScope connectionScope, AmqpMessageConverter messageConverter, EventHubsRetryPolicy retryPolicy, TransportProducerFeatures requestedFeatures = TransportProducerFeatures.None, PartitionPublishingOptionsInternal partitionOptions = null) { Argument.AssertNotNullOrEmpty(eventHubName, nameof(eventHubName)); Argument.AssertNotNull(connectionScope, nameof(connectionScope)); Argument.AssertNotNull(messageConverter, nameof(messageConverter)); Argument.AssertNotNull(retryPolicy, nameof(retryPolicy)); if (string.IsNullOrEmpty(producerIdentifier)) { producerIdentifier = Guid.NewGuid().ToString(); } EventHubName = eventHubName; PartitionId = partitionId; Identifier = producerIdentifier; RetryPolicy = retryPolicy; ConnectionScope = connectionScope; MessageConverter = messageConverter; ActiveFeatures = requestedFeatures; ActiveOptions = partitionOptions?.Clone() ?? new PartitionPublishingOptionsInternal(); SendLink = new FaultTolerantAmqpObject <SendingAmqpLink>( timeout => CreateLinkAndEnsureProducerStateAsync(partitionId, producerIdentifier, ActiveOptions, timeout, CancellationToken.None), link => { link.Session?.SafeClose(); link.SafeClose(); EventHubsEventSource.Log.FaultTolerantAmqpObjectClose(nameof(SendingAmqpLink), "", EventHubName, "", PartitionId, link.TerminalException?.Message); }); }
internal override TransportProducer CreateTransportProducer(string partitionId, TransportProducerFeatures requestedFeatures, PartitionPublishingOptions partitionOptions, EventHubsRetryPolicy retryPolicy) => TransportProducerFactory();
/// <summary> /// Creates a producer strongly aligned with the active protocol and transport, /// responsible for publishing <see cref="EventData" /> to the Event Hub. /// </summary> /// /// <param name="partitionId">The identifier of the partition to which the transport producer should be bound; if <c>null</c>, the producer is unbound.</param> /// <param name="producerIdentifier">The identifier to associate with the consumer; if <c>null</c> or <see cref="string.Empty" />, a random identifier will be generated.</param> /// <param name="requestedFeatures">The flags specifying the set of special transport features that should be opted-into.</param> /// <param name="partitionOptions">The set of options, if any, that should be considered when initializing the producer.</param> /// <param name="retryPolicy">The policy which governs retry behavior and try timeouts.</param> /// /// <returns>A <see cref="TransportProducer"/> configured in the requested manner.</returns> /// public abstract TransportProducer CreateProducer(string partitionId, string producerIdentifier, TransportProducerFeatures requestedFeatures, PartitionPublishingOptionsInternal partitionOptions, EventHubsRetryPolicy retryPolicy);
private static bool IsSequenceMeasurementRequired(TransportProducerFeatures activeFeatures) => ((activeFeatures & TransportProducerFeatures.IdempotentPublishing) != 0);