aldettinger commented on code in PR #6371:
URL: https://github.com/apache/camel-quarkus/pull/6371#discussion_r1726467488
##########
integration-test-groups/azure/azure-eventhubs/src/main/java/org/apache/camel/quarkus/component/azure/eventhubs/it/AzureEventhubsResource.java:
##########
@@ -17,77 +17,142 @@
package org.apache.camel.quarkus.component.azure.eventhubs.it;
import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
+import java.util.Map;
import java.util.Optional;
-import java.util.stream.Collectors;
-import io.quarkus.scheduler.Scheduled;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.Consumes;
import jakarta.ws.rs.GET;
import jakarta.ws.rs.POST;
import jakarta.ws.rs.Path;
+import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.Produces;
+import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.core.MediaType;
import jakarta.ws.rs.core.Response;
import org.apache.camel.CamelContext;
-import org.apache.camel.ConsumerTemplate;
import org.apache.camel.Exchange;
+import org.apache.camel.Message;
import org.apache.camel.ProducerTemplate;
+import org.apache.camel.component.azure.eventhubs.EventHubsConstants;
import org.apache.camel.component.mock.MockEndpoint;
-import org.eclipse.microprofile.config.inject.ConfigProperty;
+import org.apache.camel.util.ObjectHelper;
+import org.jboss.logging.Logger;
@Path("/azure-eventhubs")
@ApplicationScoped
public class AzureEventhubsResource {
+ private static final Logger LOG =
Logger.getLogger(AzureEventhubsResource.class);
@Inject
ProducerTemplate producerTemplate;
- @Inject
- ConsumerTemplate consumerTemplate;
-
@Inject
CamelContext context;
- @ConfigProperty(name = "azure.event.hubs.connection.string")
- Optional<String> connectionString;
-
- private volatile String message;
- private int counter = 0;
-
- /**
- * For some reason if we send just a single message, it is not always
received by the consumer.
- * Sending multiple messages seems to be more reliable.
- */
- @Scheduled(every = "1s")
- void schedule() {
- if (message != null) {
- final String endpointUri =
"azure-eventhubs:?connectionString=RAW(" + connectionString.get() + ")";
- producerTemplate.sendBody(endpointUri, message + (counter++));
+ @Path("/receive-event/{partitionId}")
+ @GET
+ @Produces(MediaType.APPLICATION_JSON)
+ public Map<String, Object> receiveEvent(@PathParam("partitionId") String
partitionId, String match) throws Exception {
+ final MockEndpoint mockEndpoint =
context.getEndpoint("mock:partition-%s-results".formatted(partitionId),
+ MockEndpoint.class);
+ List<Exchange> receivedExchanges = mockEndpoint.getReceivedExchanges();
+
+ Optional<Exchange> optionalExchange = receivedExchanges.stream()
+ .filter(exchange ->
exchange.getMessage().getBody(String.class).equals(match))
+ .findFirst();
+
+ if (optionalExchange.isEmpty()) {
+ return Collections.emptyMap();
+ }
+
+ mockEndpoint.reset();
Review Comment:
There was flaky and debugging issues in the past with mock.resetting
approach.
Isn't there a reasonable way to avoid this ? Like using a distinct mock per
use case ? Actually, do we have multiple call for the same
`mock:partition-%s-results` here ?
--
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: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]