Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 18 additions & 4 deletions src/main/java/com/jss/camel/components/rest/RestDsl.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import java.util.Objects;

import static com.jss.config.CamelConfiguration.RABBIT_URI;
import static org.apache.camel.Exchange.HTTP_RESPONSE_CODE;
import static org.springframework.http.HttpStatus.NOT_FOUND;

Expand All @@ -32,13 +33,26 @@ public void configure() throws Exception {

rest("/api")
.consumes("application/json").produces("application/json")
.post("/connection").type(ConnectionDto.class).to("direct:make-connection");
.post("/connection").type(ConnectionDto.class).to("direct:make-connection")
.delete("/delete").to("direct:delete-connection");


from("direct:make-connection")
.process(this::makeConnection);
.toF(RABBIT_URI,"no","no");
fromF(RABBIT_URI,"no","no")
.to()

from("direct:delete-connection")
.process(this::makeDelete);
}

public void makeDelete(Exchange exchange) throws Exception {
System.out.println(getContext().getRoutes());
getContext().removeRoute("myRoute");

}


public void makeConnection(Exchange exchange) throws Exception {
ConnectionDto dto = exchange.getMessage().getBody(ConnectionDto.class);
connectionProvider.setCurrentConnection(dto);
Expand All @@ -48,10 +62,10 @@ public void makeConnection(Exchange exchange) throws Exception {
System.out.println(myConnection.toString());

String rabbit_uri = String.format("rabbitmq:%s?hostname=%s&portNumber=%s&username=%s&password=%s&queue=%s&routingKey=%s&autoDelete=false",
dto.getRabbitExchange(), dto.getRabbitHost(), dto.getRabbitPort(), dto.getUsername(), dto.getPassword(), dto.getQueue(), dto.getRouting_key());
dto.getRabbitExchange(), dto.getRabbitHost(), dto.getRabbitPort(), dto.getUsername(), dto.getPassword(), dto.getQueue(), dto.getRouting_key());

String mosquitto_uri = String.format("paho:%s?brokerUrl=tcp://%s:%s",
dto.getTopic(), dto.getMosquittoHost(), dto.getMosquittoPort());
dto.getTopic(), dto.getMosquittoHost(), dto.getMosquittoPort());

CamelContext context = getContext();
context.addRoutes(new AddRoutesAtRuntimeTest.MyDynamcRouteBuilder(context, rabbit_uri, mosquitto_uri));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,12 +38,12 @@ public MyDynamcRouteBuilder(CamelContext context, String from, String to) {
@Override
public void configure() throws Exception {
from(from)
//.log(LoggingLevel.ERROR, "Before Enrichment: ${body}")
.unmarshal().json(JsonLibrary.Jackson, SensorDto.class)
.process(this::enrichSensorDto)
//.log(LoggingLevel.ERROR, "After Enrichment: ${body}")
.routeId("myRoute")
.marshal().json(JsonLibrary.Jackson, SensorDto.class)
.to(to);
.to(to)
.end();
}

private void enrichSensorDto(Exchange exchange) {
Expand Down