Github user srdo commented on a diff in the pull request:
https://github.com/apache/storm/pull/2588#discussion_r173635092
--- Diff:
external/storm-eventhubs/src/main/java/org/apache/storm/eventhubs/core/PartitionReceiverFactory.java
---
@@ -0,0 +1,57 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+
*******************************************************************************/
+
+package org.apache.storm.eventhubs.core;
+
+import com.microsoft.azure.eventhubs.EventHubClient;
+import com.microsoft.azure.eventhubs.EventPosition;
+import com.microsoft.azure.eventhubs.PartitionReceiver;
+import com.microsoft.azure.eventhubs.EventHubException;
+
+public final class PartitionReceiverFactory {
+
+ public static PartitionReceiver createReceiver(EventHubClient
ehClient, IEventFilter filter,
+ EventHubConfig
eventHubConfig, String partitionId) throws EventHubException {
+
+ if (filter instanceof OffsetFilter) {
+ return createOffsetReceiver(ehClient, (OffsetFilter) filter,
eventHubConfig, partitionId);
+ } else {
+ return createTimestampReceiver(ehClient, (TimestampFilter)
filter, eventHubConfig, partitionId);
+ }
+ }
+
+ private static PartitionReceiver createOffsetReceiver(EventHubClient
ehClient, OffsetFilter filter,
+ EventHubConfig
eventHubConfig, String partitionId) throws EventHubException {
+
+ return ehClient.createEpochReceiverSync(
+ eventHubConfig.getConsumerGroupName(),
+ partitionId,
+ EventPosition.fromOffset(filter.getOffset(), false),
--- End diff --
I think you would be better off putting this line in the OffsetFilter
implementation, and similar for TimestampFilter. That way you can have
IEventFilter declare a getOffset() method instead of having to do the
instanceof check in createReceiver.
---