com.microsoft.azure.eventhubs.EventDataUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of azure-eventhubs Show documentation
Show all versions of azure-eventhubs Show documentation
Client library for talking to Microsoft Azure Event Hubs.
/*
* Copyright (c) Microsoft. All rights reserved.
* Licensed under the MIT license. See LICENSE file in the project root for full license information.
*/
package com.microsoft.azure.eventhubs;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
import java.util.LinkedList;
import java.util.Set;
import java.util.function.Consumer;
import org.apache.qpid.proton.message.Message;
import com.microsoft.azure.servicebus.amqp.AmqpConstants;
import com.microsoft.azure.servicebus.PassByRef;
/*
* Internal utility class for EventData
*/
final class EventDataUtil {
@SuppressWarnings("serial")
static final Set RESERVED_SYSTEM_PROPERTIES = Collections.unmodifiableSet(new HashSet() {{
add(AmqpConstants.OFFSET_ANNOTATION_NAME);
add(AmqpConstants.PARTITION_KEY_ANNOTATION_NAME);
add(AmqpConstants.SEQUENCE_NUMBER_ANNOTATION_NAME);
add(AmqpConstants.ENQUEUED_TIME_UTC_ANNOTATION_NAME);
add(AmqpConstants.PUBLISHER_ANNOTATION_NAME);
}});
private EventDataUtil() {
}
static LinkedList toEventDataCollection(final Collection messages, final PassByRef lastMessageRef) {
if (messages == null) {
return null;
}
LinkedList events = new LinkedList<>();
for (Message message : messages) {
events.add(new EventData(message));
if (lastMessageRef != null)
lastMessageRef.set(message);
}
return events;
}
static Iterable toAmqpMessages(final Iterable eventDatas, final String partitionKey) {
final LinkedList messages = new LinkedList<>();
eventDatas.forEach(new Consumer() {
@Override
public void accept(EventData eventData) {
Message amqpMessage = partitionKey == null ? eventData.toAmqpMessage() : eventData.toAmqpMessage(partitionKey);
messages.add(amqpMessage);
}
});
return messages;
}
static Iterable toAmqpMessages(final Iterable eventDatas) {
return EventDataUtil.toAmqpMessages(eventDatas, null);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy