f2par0 commented on code in PR #628: URL: https://github.com/apache/camel-karaf/pull/628#discussion_r2149298507
########## tests/features/camel-azure-eventhubs/src/main/java/org/apache/karaf/camel/test/CamelAzureEventhubsRouteSupplier.java: ########## @@ -0,0 +1,101 @@ +/* + * 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.karaf.camel.test; + +import static org.apache.camel.builder.Builder.method; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Function; +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.azure.eventhubs.EventHubsComponent; +import org.apache.camel.component.azure.eventhubs.EventHubsConfiguration; +import org.apache.camel.model.RouteDefinition; +import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier; +import org.apache.karaf.camel.itests.CamelRouteSupplier; +import org.osgi.service.component.annotations.Component; + +import com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore; +import com.azure.storage.blob.BlobContainerAsyncClient; +import com.azure.storage.blob.BlobContainerClientBuilder; +import com.azure.storage.common.StorageSharedKeyCredential; + +@Component( + name = "karaf-camel-azureeventhubs-test", + immediate = true, + service = CamelRouteSupplier.class +) +public class CamelAzureEventhubsRouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier { + + private static final String TEST_ACCOUNT = System.getProperty("azure.accountName"); + private static final String TEST_ACCOUNT_KEY = System.getProperty("azure.accountKey"); + public static final String TEST_CONTAINER = "mycontainer"; + private String connectionString; + private AtomicBoolean isReceived = new AtomicBoolean(false); + + @Override + public void configure(CamelContext camelContext) { + connectionString = System.getProperty("azure.connectionString"); + final StorageSharedKeyCredential credential = + new StorageSharedKeyCredential(TEST_ACCOUNT, TEST_ACCOUNT_KEY); + + final String host = System.getProperty("azure.host"); + final String port = System.getProperty("azure.port"); + final String endpoint = "http://" + host + ":" + port + "/" + TEST_ACCOUNT; + + BlobContainerAsyncClient blobClient = new BlobContainerClientBuilder() + .endpoint(endpoint) + .containerName(TEST_CONTAINER) + .credential(credential) + .buildAsyncClient(); + blobClient.createIfNotExists().block(); + + EventHubsConfiguration config = new EventHubsConfiguration(); + config.setCheckpointStore(new BlobCheckpointStore(blobClient)); + config.setBlobAccountName(TEST_ACCOUNT); + config.setBlobContainerName(TEST_CONTAINER); + config.setBlobStorageSharedKeyCredential(credential); + config.setBlobAccessKey(TEST_ACCOUNT_KEY); + config.setConnectionString(connectionString); + + EventHubsComponent component = new EventHubsComponent(); + component.setConfiguration(config); + camelContext.addComponent("azure-eventhubs", component); + } + + + @Override + protected Function<RouteBuilder, RouteDefinition> consumerRoute() { + return builder-> builder.fromF("azure-eventhubs:?connectionString=%sEntityPath=eh1", connectionString) + .log("Received message from Event Hub: ${body}") + .process( ex -> isReceived.set(true)); + } + + @Override + protected void configureProducer(RouteBuilder builder, RouteDefinition producerRoute) { + producerRoute.log("sending a message: ${body}") //delay to make sure the consumer is connected Review Comment: the first solution I did was to introduce a 5s delay before sending the message, and then I used this loop wich is more robust and efficient. Comment updated ########## tests/features/camel-azure-eventhubs/src/main/java/org/apache/karaf/camel/test/CamelAzureEventhubsRouteSupplier.java: ########## @@ -0,0 +1,101 @@ +/* + * 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.karaf.camel.test; + +import static org.apache.camel.builder.Builder.method; + +import java.util.concurrent.atomic.AtomicBoolean; +import java.util.function.Function; +import org.apache.camel.CamelContext; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.azure.eventhubs.EventHubsComponent; +import org.apache.camel.component.azure.eventhubs.EventHubsConfiguration; +import org.apache.camel.model.RouteDefinition; +import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier; +import org.apache.karaf.camel.itests.CamelRouteSupplier; +import org.osgi.service.component.annotations.Component; + +import com.azure.messaging.eventhubs.checkpointstore.blob.BlobCheckpointStore; +import com.azure.storage.blob.BlobContainerAsyncClient; +import com.azure.storage.blob.BlobContainerClientBuilder; +import com.azure.storage.common.StorageSharedKeyCredential; + +@Component( + name = "karaf-camel-azureeventhubs-test", + immediate = true, + service = CamelRouteSupplier.class +) +public class CamelAzureEventhubsRouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier { + + private static final String TEST_ACCOUNT = System.getProperty("azure.accountName"); + private static final String TEST_ACCOUNT_KEY = System.getProperty("azure.accountKey"); + public static final String TEST_CONTAINER = "mycontainer"; + private String connectionString; + private AtomicBoolean isReceived = new AtomicBoolean(false); Review Comment: Yes, it can be final. It is required to have the producer sending message until one is received by the consumer. In most cases the producer is started before the consumer and then no message is received. -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@camel.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org