예제 #1
0
        public void ManagesSingleReadOnlyMemoryWithoutCopying()
        {
            var singleReadOnlyMemory = new ReadOnlyMemory <byte>(new byte[] { 1, 2, 3 });
            var message = new AmqpMessageBody(MessageBody.FromReadOnlyMemorySegment(singleReadOnlyMemory));

            message.TryGetData(out var body);
            var fromReadOnlyMemorySegments = (ReadOnlyMemory <byte>)MessageBody.FromReadOnlyMemorySegments(body);

            Assert.That(fromReadOnlyMemorySegments, Is.EqualTo(singleReadOnlyMemory));
        }
예제 #2
0
        public void ManagesSingleReadOnlyMemoryWithoutCopying()
        {
            ReadOnlyMemory <byte> singleReadOnlyMemory = new byte[] { 1, 2, 3 };

            var message = new AmqpMessageBody(MessageBody.FromReadOnlyMemorySegment(singleReadOnlyMemory));

            message.TryGetData(out var body);
            ReadOnlyMemory <byte> fromReadOnlyMemorySegments = MessageBody.FromReadOnlyMemorySegments(body);

            Assert.IsTrue(singleReadOnlyMemory.Equals(fromReadOnlyMemorySegments));
        }
예제 #3
0
        /// <summary>
        ///   Initializes a new instance of the <see cref="EventData"/> class.
        /// </summary>
        ///
        /// <param name="eventBody">The raw data as binary to use as the body of the event.</param>
        /// <param name="properties">The set of free-form event properties to send with the event.</param>
        /// <param name="systemProperties">The set of system properties received from the Event Hubs service.</param>
        /// <param name="sequenceNumber">The sequence number assigned to the event when it was enqueued in the associated Event Hub partition.</param>
        /// <param name="offset">The offset of the event when it was received from the associated Event Hub partition.</param>
        /// <param name="enqueuedTime">The date and time, in UTC, of when the event was enqueued in the Event Hub partition.</param>
        /// <param name="partitionKey">The partition hashing key applied to the batch that the associated <see cref="EventData"/>, was sent with.</param>
        /// <param name="lastPartitionSequenceNumber">The sequence number that was last enqueued into the Event Hub partition.</param>
        /// <param name="lastPartitionOffset">The offset that was last enqueued into the Event Hub partition.</param>
        /// <param name="lastPartitionEnqueuedTime">The date and time, in UTC, of the event that was last enqueued into the Event Hub partition.</param>
        /// <param name="lastPartitionPropertiesRetrievalTime">The date and time, in UTC, that the last event information for the Event Hub partition was retrieved from the service.</param>
        /// <param name="publishedSequenceNumber">The publishing sequence number assigned to the event at the time it was successfully published.</param>
        /// <param name="pendingPublishSequenceNumber">The publishing sequence number assigned to the event as part of a publishing operation.</param>
        /// <param name="pendingProducerGroupId">The producer group identifier assigned to the event as part of a publishing operation.</param>
        /// <param name="pendingOwnerLevel">The producer owner level assigned to the event as part of a publishing operation.</param>
        ///
        internal EventData(BinaryData eventBody,
                           IDictionary <string, object> properties = null,
                           IReadOnlyDictionary <string, object> systemProperties = null,
                           long?sequenceNumber                                 = null,
                           long?offset                                         = null,
                           DateTimeOffset?enqueuedTime                         = null,
                           string partitionKey                                 = null,
                           long?lastPartitionSequenceNumber                    = null,
                           long?lastPartitionOffset                            = null,
                           DateTimeOffset?lastPartitionEnqueuedTime            = null,
                           DateTimeOffset?lastPartitionPropertiesRetrievalTime = null,
                           int?publishedSequenceNumber                         = null,
                           int?pendingPublishSequenceNumber                    = null,
                           long?pendingProducerGroupId                         = null,
                           short?pendingOwnerLevel                             = null)
        {
            Argument.AssertNotNull(eventBody, nameof(eventBody));
            _amqpMessage = new AmqpAnnotatedMessage(AmqpMessageBody.FromData(MessageBody.FromReadOnlyMemorySegment(eventBody.ToMemory())));

            _amqpMessage.PopulateFromEventProperties(
                properties,
                sequenceNumber,
                offset,
                enqueuedTime,
                partitionKey,
                lastPartitionSequenceNumber,
                lastPartitionOffset,
                lastPartitionEnqueuedTime,
                lastPartitionPropertiesRetrievalTime);

            // If there was a set of system properties explicitly provided, then
            // override the default projection with them.

            if (systemProperties != null)
            {
                _systemProperties = systemProperties;
            }

            // Set the idempotent publishing state.

            PublishedSequenceNumber      = publishedSequenceNumber;
            PendingPublishSequenceNumber = pendingPublishSequenceNumber;
            PendingProducerGroupId       = pendingProducerGroupId;
            PendingProducerOwnerLevel    = pendingOwnerLevel;
        }
예제 #4
0
        /// <summary>
        /// Creates a new message from the specified payload.
        /// </summary>
        /// <param name="body">The payload of the message in bytes.</param>
        public ServiceBusMessage(ReadOnlyMemory <byte> body)
        {
            AmqpMessageBody amqpBody = new AmqpMessageBody(MessageBody.FromReadOnlyMemorySegment(body));

            AmqpMessage = new AmqpAnnotatedMessage(amqpBody);
        }