Skip to content
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

Ensure Quarkus Vertx instance is set on the camel component when not using camel-quarkus-main #1422

Merged
merged 2 commits into from
Jun 26, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/modules/ROOT/pages/extensions/vertx.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,9 @@ Please refer to the above link for usage and configuration details.
----

Check the xref:user-guide/index.adoc[User guide] for more information about writing Camel Quarkus applications.

== Additional Camel Quarkus configuration

The extension leverages https://quarkus.io/guides/vertx[Quarkus Vert.x]. Various aspects of the Vert.x runtime can be configured
via the options outlined in the https://quarkus.io/guides/all-config#quarkus-vertx-core_quarkus-vertx-core[configuration guide].

Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,12 @@
package org.apache.camel.quarkus.component.vertx.deployment;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.ExecutionTime;
import io.quarkus.deployment.annotations.Record;
import io.quarkus.deployment.builditem.FeatureBuildItem;
import io.quarkus.vertx.deployment.VertxBuildItem;
import io.vertx.core.Vertx;
import org.apache.camel.component.vertx.VertxComponent;
import org.apache.camel.quarkus.component.vertx.CamelVertxRecorder;
import org.apache.camel.quarkus.core.deployment.spi.CamelRuntimeBeanBuildItem;

class VertxProcessor {
Expand All @@ -31,8 +34,10 @@ FeatureBuildItem feature() {
return new FeatureBuildItem(FEATURE);
}

@Record(ExecutionTime.RUNTIME_INIT)
@BuildStep
CamelRuntimeBeanBuildItem configureVertxRegistryBean(VertxBuildItem vertx) {
return new CamelRuntimeBeanBuildItem("vertx", Vertx.class.getName(), vertx.getVertx());
CamelRuntimeBeanBuildItem configureVertxRegistryBean(CamelVertxRecorder recorder, VertxBuildItem vertx) {
return new CamelRuntimeBeanBuildItem("vertx", VertxComponent.class.getName(),
recorder.createVertxComponent(vertx.getVertx()));
}
}
2 changes: 2 additions & 0 deletions extensions/vertx/runtime/src/main/doc/configuration.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
The extension leverages https://quarkus.io/guides/vertx[Quarkus Vert.x]. Various aspects of the Vert.x runtime can be configured
via the options outlined in the https://quarkus.io/guides/all-config#quarkus-vertx-core_quarkus-vertx-core[configuration guide].
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* 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.camel.quarkus.component.vertx;

import io.quarkus.runtime.RuntimeValue;
import io.quarkus.runtime.annotations.Recorder;
import io.vertx.core.Vertx;
import org.apache.camel.component.vertx.VertxComponent;

@Recorder
public class CamelVertxRecorder {

public RuntimeValue<VertxComponent> createVertxComponent(RuntimeValue<Vertx> vertx) {
VertxComponent component = new VertxComponent();
component.setVertx(vertx.getValue());
return new RuntimeValue<>(component);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,20 +20,30 @@

import javax.inject.Inject;
import javax.ws.rs.Consumes;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import io.vertx.core.Vertx;
import org.apache.camel.CamelContext;
import org.apache.camel.ProducerTemplate;
import org.apache.camel.component.vertx.VertxComponent;

@Path("/vertx")
public class VertxResource {

@Inject
ProducerTemplate producerTemplate;

@Inject
CamelContext camelContext;

@Inject
Vertx vertx;

@Path("/post")
@POST
@Consumes(MediaType.TEXT_PLAIN)
Expand All @@ -42,4 +52,12 @@ public Response post(String message) throws Exception {
String result = producerTemplate.requestBody("direct:start", message, String.class);
return Response.created(new URI("https://camel.apache.org/")).entity(result).build();
}

@Path("/verify/instance")
@GET
@Produces(MediaType.TEXT_PLAIN)
public boolean quarkusVertxInstanceUsedInVertxComponent() {
VertxComponent component = camelContext.getComponent("vertx", VertxComponent.class);
return component.getVertx() == vertx;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,14 @@ class VertxTest {

@Test
public void testVertxComponent() {
// Verify that the Vertx instance set up by the Quarkus extension
// is the one used in the Camel component
RestAssured.given()
.get("/vertx/verify/instance")
.then()
.statusCode(200)
.body(is("true"));

String message = "Camel Quarkus Vert.x";
RestAssured.given()
.contentType(ContentType.TEXT)
Expand Down