-
Notifications
You must be signed in to change notification settings - Fork 366
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Azure Servicebus Source Connector #1222
Closed
Closed
Changes from 7 commits
Commits
Show all changes
13 commits
Select commit
Hold shift + click to select a range
e2e4928
stub module with simple Config and tasks for Connector
GoMati-MU e390609
initial working version of connector
GoMati-MU 478f867
minor test fixes
GoMati-MU bd4c866
updating azure dependencies
GoMati-MU b1e20b2
reverting to lombok val since it's not getting deprecated
GoMati-MU 2d47ceb
added explicit message commit to service bus
GoMati-MU b7fe5ef
adding testcase
GoMati-MU c506b2a
PR comments pt. 1
GoMati-MU 634953a
spotless changes
GoMati-MU a745853
PR comments pt.2
GoMati-MU 2c54bf2
Merge branch 'master' into feat/azure-servicebus-connector
GoMati-MU d373f76
PR comments pt.3
GoMati-MU c3bffe6
PR comments pt.4
GoMati-MU File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
java-connectors/kafka-connect-azure-servicebus/build.gradle
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
project(':kafka-connect-azure-servicebus') { | ||
|
||
|
||
test { | ||
maxParallelForks = 1 | ||
} | ||
|
||
dependencies { | ||
implementation project(':kafka-connect-common') | ||
implementation project(':kafka-connect-query-language') | ||
|
||
// Azure Service Bus dependencies | ||
implementation group: 'com.azure', name: 'azure-core', version: '1.49.0' | ||
implementation group: 'com.azure', name: 'azure-messaging-servicebus', version: '7.17.0' | ||
|
||
|
||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
.../lenses/streamreactor/connect/azure/servicebus/config/AzureServiceBusConfigConstants.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
/* | ||
* Copyright 2017-2024 Lenses.io Ltd | ||
* | ||
* Licensed 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 io.lenses.streamreactor.connect.azure.servicebus.config; | ||
|
||
import io.lenses.streamreactor.connect.azure.servicebus.source.AzureServiceBusSourceConnector; | ||
|
||
/** | ||
* Class to indicate String constants used in Service Bus Connectors Config. | ||
*/ | ||
public class AzureServiceBusConfigConstants { | ||
|
||
private static final String DOT = "."; | ||
public static final String CONNECTOR_PREFIX = "connect.servicebus"; | ||
public static final String SOURCE_CONNECTOR_PREFIX = CONNECTOR_PREFIX + DOT + "source"; | ||
|
||
public static final String CONNECTOR_NAME = "name"; | ||
public static final String CONNECTOR_NAME_DOC = "Connector's name"; | ||
public static final String CONNECTOR_NAME_DEFAULT = AzureServiceBusSourceConnector.class.getSimpleName(); | ||
public static final String CONNECTION_STRING = CONNECTOR_PREFIX + DOT + "connection.string"; | ||
public static final String CONNECTION_STRING_DOC = "Azure ServiceBus Connection String"; | ||
public static final String KCQL_CONFIG = CONNECTOR_PREFIX + DOT + "kcql"; | ||
public static final String KCQL_DOC = | ||
"KCQL expression describing field selection and data routing to the target."; | ||
|
||
} |
77 changes: 77 additions & 0 deletions
77
.../io/lenses/streamreactor/connect/azure/servicebus/config/AzureServiceBusSourceConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* Copyright 2017-2024 Lenses.io Ltd | ||
* | ||
* Licensed 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 io.lenses.streamreactor.connect.azure.servicebus.config; | ||
|
||
import io.lenses.streamreactor.common.config.base.BaseConfig; | ||
import io.lenses.streamreactor.common.config.base.intf.ConnectorPrefixed; | ||
import java.util.Map; | ||
import lombok.Getter; | ||
import org.apache.kafka.common.config.ConfigDef; | ||
import org.apache.kafka.common.config.ConfigDef.Importance; | ||
import org.apache.kafka.common.config.ConfigDef.Type; | ||
|
||
/** | ||
* Service Bus Connector Configuration class. | ||
*/ | ||
public class AzureServiceBusSourceConfig extends BaseConfig implements ConnectorPrefixed { | ||
|
||
@Getter | ||
private static final ConfigDef configDefinition; | ||
|
||
public static final String CONNECTION_GROUP = "Connection"; | ||
public static final String BASE_GROUP = "Base"; | ||
|
||
static { | ||
configDefinition = | ||
new ConfigDef() | ||
.define(AzureServiceBusConfigConstants.CONNECTOR_NAME, | ||
Type.STRING, | ||
AzureServiceBusConfigConstants.CONNECTOR_NAME_DEFAULT, | ||
Importance.HIGH, | ||
AzureServiceBusConfigConstants.CONNECTOR_NAME_DOC, | ||
BASE_GROUP, | ||
1, | ||
ConfigDef.Width.LONG, | ||
AzureServiceBusConfigConstants.CONNECTOR_NAME | ||
).define(AzureServiceBusConfigConstants.CONNECTION_STRING, | ||
Type.STRING, | ||
Importance.HIGH, | ||
AzureServiceBusConfigConstants.CONNECTION_STRING_DOC, | ||
CONNECTION_GROUP, | ||
2, | ||
ConfigDef.Width.LONG, | ||
AzureServiceBusConfigConstants.CONNECTION_STRING | ||
).define(AzureServiceBusConfigConstants.KCQL_CONFIG, | ||
Type.STRING, | ||
Importance.HIGH, | ||
AzureServiceBusConfigConstants.KCQL_DOC, | ||
"Mappings", | ||
1, | ||
ConfigDef.Width.LONG, | ||
AzureServiceBusConfigConstants.KCQL_CONFIG | ||
); | ||
} | ||
|
||
public AzureServiceBusSourceConfig(Map<?, ?> properties) { | ||
super(AzureServiceBusConfigConstants.CONNECTOR_PREFIX, getConfigDefinition(), properties); | ||
} | ||
|
||
@Override | ||
public String connectorPrefix() { | ||
return connectorPrefix; | ||
} | ||
|
||
} |
35 changes: 35 additions & 0 deletions
35
...io/lenses/streamreactor/connect/azure/servicebus/mapping/AzureServiceBusSourceRecord.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
/* | ||
* Copyright 2017-2024 Lenses.io Ltd | ||
* | ||
* Licensed 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 io.lenses.streamreactor.connect.azure.servicebus.mapping; | ||
|
||
import java.util.Map; | ||
import lombok.ToString; | ||
import org.apache.kafka.connect.data.Schema; | ||
import org.apache.kafka.connect.header.Header; | ||
import org.apache.kafka.connect.source.SourceRecord; | ||
|
||
/** | ||
* Implementation of {@link SourceRecord} for Microsoft Azure EventHubs. | ||
*/ | ||
@ToString(callSuper = true) | ||
public class AzureServiceBusSourceRecord extends SourceRecord { | ||
|
||
public AzureServiceBusSourceRecord(Map<String, ?> sourcePartition, Map<String, ?> sourceOffset, | ||
String topic, Integer partition, Schema keySchema, Object key, | ||
Schema valueSchema, Object value, Long timestamp, Iterable<Header> headers) { | ||
super(sourcePartition, sourceOffset, topic, partition, keySchema, key, valueSchema, value, timestamp, headers); | ||
davidsloan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
...lenses/streamreactor/connect/azure/servicebus/mapping/ServiceBusToSourceRecordMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2017-2024 Lenses.io Ltd | ||
* | ||
* Licensed 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 io.lenses.streamreactor.connect.azure.servicebus.mapping; | ||
|
||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.CONTENT_TYPE; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.CORRELATION_ID; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.DEAD_LETTER_SOURCE; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.DELIVERY_COUNT; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.ENQUEUED_TIME_UTC; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.GET_TO; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.LABEL; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.LOCKED_UNTIL_UTC; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.LOCK_TOKEN; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.MESSAGE_BODY; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.PARTITION_KEY; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.REPLY_TO; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.REPLY_TO_SESSION_ID; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.SEQUENCE_NUMBER; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.SESSION_ID; | ||
import static io.lenses.streamreactor.connect.azure.servicebus.mapping.ServiceBusValueSchemaField.TIME_TO_LIVE; | ||
|
||
import com.azure.messaging.servicebus.ServiceBusReceivedMessage; | ||
import io.lenses.streamreactor.connect.azure.servicebus.source.AzureServiceBusSourceConnector; | ||
import java.util.Map; | ||
import org.apache.kafka.connect.data.Schema; | ||
import org.apache.kafka.connect.data.SchemaBuilder; | ||
import org.apache.kafka.connect.data.Struct; | ||
import org.apache.kafka.connect.header.ConnectHeaders; | ||
import org.apache.kafka.connect.source.SourceRecord; | ||
|
||
/** | ||
* Class that maps {@link ServiceBusReceivedMessage} to Kafka Connect {@link SourceRecord}. | ||
*/ | ||
public class ServiceBusToSourceRecordMapper { | ||
|
||
public static final Schema VALUE_SCHEMA; | ||
|
||
static { | ||
SchemaBuilder structSchemaBuilder = SchemaBuilder.struct(); | ||
ServiceBusValueSchemaField.getAllFields() | ||
.forEach(field -> structSchemaBuilder.field(field.name(), field.schema())); | ||
VALUE_SCHEMA = structSchemaBuilder.build(); | ||
} | ||
|
||
private ServiceBusToSourceRecordMapper() { | ||
} | ||
|
||
/** | ||
* Method to make SourceRecord out of ServiceBusReceivedMessage with key and body as structure. | ||
* | ||
* @param serviceBusMessage original Service Bus message | ||
* @param outputTopic Output topic for record | ||
* @param partitionKey AzureTopicPartitionKey to indicate topic and partition | ||
* @param offsetMap AzureOffsetMarker to indicate offset | ||
* @return mapped SourceRecord | ||
*/ | ||
public static SourceRecord mapSingleServiceBusMessage(ServiceBusReceivedMessage serviceBusMessage, String outputTopic, | ||
Map<String, String> partitionKey, Map<String, Object> offsetMap) { | ||
String key = serviceBusMessage.getMessageId(); | ||
Struct valueObject = new Struct(VALUE_SCHEMA); | ||
|
||
mapValuesFromServiceBusMessage(valueObject, serviceBusMessage); | ||
return new AzureServiceBusSourceRecord(partitionKey, offsetMap, outputTopic, null, Schema.STRING_SCHEMA, key, | ||
VALUE_SCHEMA, valueObject, serviceBusMessage.getEnqueuedTime().toEpochSecond(), new ConnectHeaders()); | ||
} | ||
|
||
private static void mapValuesFromServiceBusMessage(Struct targetObject, ServiceBusReceivedMessage serviceBusMessage) { | ||
targetObject.put(DELIVERY_COUNT, serviceBusMessage.getDeliveryCount()); | ||
targetObject.put(ENQUEUED_TIME_UTC, serviceBusMessage.getEnqueuedTime().toEpochSecond()); | ||
targetObject.put(CONTENT_TYPE, serviceBusMessage.getContentType()); | ||
targetObject.put(LABEL, AzureServiceBusSourceConnector.class.getSimpleName()); | ||
targetObject.put(CORRELATION_ID, serviceBusMessage.getCorrelationId()); | ||
targetObject.put(PARTITION_KEY, serviceBusMessage.getPartitionKey()); | ||
targetObject.put(REPLY_TO, serviceBusMessage.getReplyTo()); | ||
targetObject.put(REPLY_TO_SESSION_ID, serviceBusMessage.getReplyToSessionId()); | ||
targetObject.put(DEAD_LETTER_SOURCE, serviceBusMessage.getDeadLetterSource()); | ||
targetObject.put(TIME_TO_LIVE, serviceBusMessage.getTimeToLive().toMillis()); | ||
targetObject.put(LOCKED_UNTIL_UTC, serviceBusMessage.getLockedUntil().toEpochSecond()); | ||
targetObject.put(SEQUENCE_NUMBER, serviceBusMessage.getSequenceNumber()); | ||
targetObject.put(SESSION_ID, serviceBusMessage.getSessionId()); | ||
targetObject.put(LOCK_TOKEN, serviceBusMessage.getLockToken()); | ||
targetObject.put(MESSAGE_BODY, serviceBusMessage.getBody().toBytes()); | ||
targetObject.put(GET_TO, serviceBusMessage.getTo()); | ||
} | ||
davidsloan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wanted to point you to this
Customers won't always be able to use connection string for connecting to azure, especially if they are running on an Azure instance in which they will have default chain from the instance profile. I believe the original PR was more complete in this respect?
But if we can we should identify code we can reuse here and move it into the Java repo so we are not inventing the wheel and duplicating throughout the codebase. I did similar recently for GCP cloud connectors, so can help with this if you would like.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There are two ways endorsed in official Service Bus docs: one being Passwordless, second being Connection String. Since the first one will work using specifically-installed Azure commandline and our connectors are being ran inside docker container, it would require us to include Azure commandline and ways to work with it within Lenses Box (which will no doubt be huge amounts of work).
Connection String already proved to work for our clients in other Azure connectors, so that's why I've chosen to implement this path.
My take on it is: unless we get a specific requirement to support another type of authentication, let's just use what we have (as this is another feature that we don't know if ever will be used yet)