From 1047d07eaff684817a781b74ed8e43e916d2bb51 Mon Sep 17 00:00:00 2001 From: Tihomir Surdilovic Date: Sun, 18 Feb 2024 20:22:36 -0500 Subject: [PATCH] SpringBoot - Apache Camel Sample Signed-off-by: Tihomir Surdilovic --- README.md | 2 +- build.gradle | 1 + springboot/build.gradle | 2 + .../samples/springboot/SamplesController.java | 8 +- .../samples/springboot/camel/CamelConfig.java | 55 +++++++++++ .../springboot/camel/CamelResource.java | 41 +++++++++ .../samples/springboot/camel/CamelRoutes.java | 51 ++++++++++ .../samples/springboot/camel/OfficeOrder.java | 92 +++++++++++++++++++ .../springboot/camel/OrderActivity.java | 28 ++++++ .../springboot/camel/OrderActivityImpl.java | 37 ++++++++ .../springboot/camel/OrderRepository.java | 26 ++++++ .../springboot/camel/OrderWorkflow.java | 30 ++++++ .../springboot/camel/OrderWorkflowImpl.java | 40 ++++++++ .../samples/springboot/camel/README.md | 12 +++ springboot/src/main/resources/data.sql | 12 ++- .../src/main/resources/templates/camel.html | 27 ++++++ .../src/main/resources/templates/index.html | 3 + .../samples/springboot/CamelSampleTest.java | 70 ++++++++++++++ 18 files changed, 534 insertions(+), 3 deletions(-) create mode 100644 springboot/src/main/java/io/temporal/samples/springboot/camel/CamelConfig.java create mode 100644 springboot/src/main/java/io/temporal/samples/springboot/camel/CamelResource.java create mode 100644 springboot/src/main/java/io/temporal/samples/springboot/camel/CamelRoutes.java create mode 100644 springboot/src/main/java/io/temporal/samples/springboot/camel/OfficeOrder.java create mode 100644 springboot/src/main/java/io/temporal/samples/springboot/camel/OrderActivity.java create mode 100644 springboot/src/main/java/io/temporal/samples/springboot/camel/OrderActivityImpl.java create mode 100644 springboot/src/main/java/io/temporal/samples/springboot/camel/OrderRepository.java create mode 100644 springboot/src/main/java/io/temporal/samples/springboot/camel/OrderWorkflow.java create mode 100644 springboot/src/main/java/io/temporal/samples/springboot/camel/OrderWorkflowImpl.java create mode 100644 springboot/src/main/java/io/temporal/samples/springboot/camel/README.md create mode 100644 springboot/src/main/resources/templates/camel.html create mode 100644 springboot/src/test/java/io/temporal/samples/springboot/CamelSampleTest.java diff --git a/README.md b/README.md index c63280cd..f04500e1 100644 --- a/README.md +++ b/README.md @@ -160,7 +160,7 @@ More info on each sample: - [**Synchronous Update**](/springboot/src/main/java/io/temporal/samples/springboot/update): Learn how to use Synchronous Update feature with this purchase sample - [**Kafka Request / Reply**](/springboot/src/main/java/io/temporal/samples/springboot/kafka): Sample showing possible integration with event streaming platforms such as Kafka - [**Customize Options**](/springboot/src/main/java/io/temporal/samples/springboot/customize): Sample showing how to customize options such as WorkerOptions, WorkerFactoryOptions, etc (see options config [here](springboot/src/main/java/io/temporal/samples/springboot/customize/TemporalOptionsConfig.java)) - +- [**Apache Camel Route**](/springboot/src/main/java/io/temporal/samples/springboot/camel): Sample showing how to start Workflow execution from a Camel Route #### Temporal Cloud To run any of the SpringBoot samples in your Temporal Cloud namespace: diff --git a/build.gradle b/build.gradle index 991cbb7c..6195b64f 100644 --- a/build.gradle +++ b/build.gradle @@ -29,6 +29,7 @@ subprojects { otelVersion = '1.30.1' otelVersionAlpha = "${otelVersion}-alpha" javaSDKVersion = '1.22.3' + camelVersion = '3.22.1' jarVersion = '1.0.0' } diff --git a/springboot/build.gradle b/springboot/build.gradle index 569e1cc9..02805f70 100644 --- a/springboot/build.gradle +++ b/springboot/build.gradle @@ -9,6 +9,8 @@ dependencies { // we set this as impl depends to use embedded kafka in samples not just tests implementation "org.springframework.kafka:spring-kafka-test" implementation "io.temporal:temporal-spring-boot-starter-alpha:$javaSDKVersion" + implementation "org.apache.camel.springboot:camel-spring-boot-starter:$camelVersion" + implementation "org.apache.camel.springboot:camel-servlet-starter:$camelVersion" runtimeOnly "io.micrometer:micrometer-registry-prometheus" runtimeOnly "com.h2database:h2" testImplementation "org.springframework.boot:spring-boot-starter-test" diff --git a/springboot/src/main/java/io/temporal/samples/springboot/SamplesController.java b/springboot/src/main/java/io/temporal/samples/springboot/SamplesController.java index 6d854070..a9799d09 100644 --- a/springboot/src/main/java/io/temporal/samples/springboot/SamplesController.java +++ b/springboot/src/main/java/io/temporal/samples/springboot/SamplesController.java @@ -127,7 +127,7 @@ ResponseEntity purchase(@RequestBody Purchase purchase) { } @GetMapping("/kafka") - public String afka(Model model) { + public String kafka(Model model) { model.addAttribute("sample", "Kafka Request / Reply"); return "kafka"; } @@ -176,4 +176,10 @@ ResponseEntity customizeSample() { // bypass thymeleaf, don't return template name just result return new ResponseEntity<>("\"" + workflow.execute() + "\"", HttpStatus.OK); } + + @GetMapping("/camel") + public String camel(Model model) { + model.addAttribute("sample", "Camel Route"); + return "camel"; + } } diff --git a/springboot/src/main/java/io/temporal/samples/springboot/camel/CamelConfig.java b/springboot/src/main/java/io/temporal/samples/springboot/camel/CamelConfig.java new file mode 100644 index 00000000..febb7846 --- /dev/null +++ b/springboot/src/main/java/io/temporal/samples/springboot/camel/CamelConfig.java @@ -0,0 +1,55 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.temporal.samples.springboot.camel; + +import org.apache.camel.CamelContext; +import org.apache.camel.ConsumerTemplate; +import org.apache.camel.ProducerTemplate; +import org.apache.camel.component.servlet.CamelHttpTransportServlet; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.web.servlet.ServletRegistrationBean; +import org.springframework.context.annotation.Bean; +import org.springframework.context.annotation.Configuration; +import org.springframework.context.annotation.Profile; + +@Configuration() +@Profile("!test") +public class CamelConfig { + @Autowired private CamelContext camelContext; + + @Bean + ServletRegistrationBean servletRegistrationBean() { + String contextPath = "/temporalapp"; + ServletRegistrationBean servlet = + new ServletRegistrationBean(new CamelHttpTransportServlet(), contextPath + "/*"); + servlet.setName("CamelServlet"); + return servlet; + } + + @Bean + ProducerTemplate producerTemplate() { + return camelContext.createProducerTemplate(); + } + + @Bean + ConsumerTemplate consumerTemplate() { + return camelContext.createConsumerTemplate(); + } +} diff --git a/springboot/src/main/java/io/temporal/samples/springboot/camel/CamelResource.java b/springboot/src/main/java/io/temporal/samples/springboot/camel/CamelResource.java new file mode 100644 index 00000000..43cb142e --- /dev/null +++ b/springboot/src/main/java/io/temporal/samples/springboot/camel/CamelResource.java @@ -0,0 +1,41 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.temporal.samples.springboot.camel; + +import java.util.List; +import org.apache.camel.ProducerTemplate; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.ResponseBody; +import org.springframework.web.bind.annotation.RestController; + +@RestController +public class CamelResource { + @Autowired private ProducerTemplate producerTemplate; + + @GetMapping("/orders") + @ResponseBody + public List getProductsByCategory() { + producerTemplate.start(); + List orders = producerTemplate.requestBody("direct:getOrders", null, List.class); + producerTemplate.stop(); + return orders; + } +} diff --git a/springboot/src/main/java/io/temporal/samples/springboot/camel/CamelRoutes.java b/springboot/src/main/java/io/temporal/samples/springboot/camel/CamelRoutes.java new file mode 100644 index 00000000..42d96465 --- /dev/null +++ b/springboot/src/main/java/io/temporal/samples/springboot/camel/CamelRoutes.java @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.temporal.samples.springboot.camel; + +import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; +import org.apache.camel.builder.RouteBuilder; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +public class CamelRoutes extends RouteBuilder { + + @Autowired private WorkflowClient workflowClient; + + @Override + public void configure() { + from("direct:getOrders") + .routeId("direct-getOrders") + .tracing() + .process( + exchange -> { + OrderWorkflow workflow = + workflowClient.newWorkflowStub( + OrderWorkflow.class, + WorkflowOptions.newBuilder() + .setWorkflowId("CamelSampleWorkflow") + .setTaskQueue("CamelSampleTaskQueue") + .build()); + exchange.getIn().setBody(workflow.start()); + }) + .end(); + } +} diff --git a/springboot/src/main/java/io/temporal/samples/springboot/camel/OfficeOrder.java b/springboot/src/main/java/io/temporal/samples/springboot/camel/OfficeOrder.java new file mode 100644 index 00000000..82b998a2 --- /dev/null +++ b/springboot/src/main/java/io/temporal/samples/springboot/camel/OfficeOrder.java @@ -0,0 +1,92 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.temporal.samples.springboot.camel; + +import javax.persistence.*; + +@Entity +@Table(name = "officeorder") +public class OfficeOrder { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Integer id; + + @Column(nullable = false) + private String number; + + @Column(nullable = false) + private String desc; + + @Column(nullable = false) + private String date; + + @Column(nullable = false) + private double price; + + public OfficeOrder() {} + + public OfficeOrder(Integer id, String number, String desc, String date, double price) { + this.id = id; + this.number = number; + this.desc = desc; + this.date = date; + this.price = price; + } + + public String getDesc() { + return desc; + } + + public void setDesc(String desc) { + this.desc = desc; + } + + public String getNumber() { + return number; + } + + public Integer getId() { + return id; + } + + public void setId(Integer id) { + this.id = id; + } + + public void setNumber(String number) { + this.number = number; + } + + public String getDate() { + return date; + } + + public void setDate(String date) { + this.date = date; + } + + public double getPrice() { + return price; + } + + public void setPrice(double price) { + this.price = price; + } +} diff --git a/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderActivity.java b/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderActivity.java new file mode 100644 index 00000000..f94d6ecf --- /dev/null +++ b/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderActivity.java @@ -0,0 +1,28 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.temporal.samples.springboot.camel; + +import io.temporal.activity.ActivityInterface; +import java.util.List; + +@ActivityInterface +public interface OrderActivity { + List getOrders(); +} diff --git a/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderActivityImpl.java b/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderActivityImpl.java new file mode 100644 index 00000000..f87b5c5b --- /dev/null +++ b/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderActivityImpl.java @@ -0,0 +1,37 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.temporal.samples.springboot.camel; + +import io.temporal.spring.boot.ActivityImpl; +import java.util.List; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Component; + +@Component +@ActivityImpl(taskQueues = "CamelSampleTaskQueue") +public class OrderActivityImpl implements OrderActivity { + + @Autowired OrderRepository repository; + + @Override + public List getOrders() { + return repository.findAll(); + } +} diff --git a/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderRepository.java b/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderRepository.java new file mode 100644 index 00000000..25595511 --- /dev/null +++ b/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderRepository.java @@ -0,0 +1,26 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.temporal.samples.springboot.camel; + +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +@Repository +public interface OrderRepository extends JpaRepository {} diff --git a/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderWorkflow.java b/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderWorkflow.java new file mode 100644 index 00000000..067d92bc --- /dev/null +++ b/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderWorkflow.java @@ -0,0 +1,30 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.temporal.samples.springboot.camel; + +import io.temporal.workflow.WorkflowInterface; +import io.temporal.workflow.WorkflowMethod; +import java.util.List; + +@WorkflowInterface +public interface OrderWorkflow { + @WorkflowMethod + public List start(); +} diff --git a/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderWorkflowImpl.java b/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderWorkflowImpl.java new file mode 100644 index 00000000..60a129e3 --- /dev/null +++ b/springboot/src/main/java/io/temporal/samples/springboot/camel/OrderWorkflowImpl.java @@ -0,0 +1,40 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.temporal.samples.springboot.camel; + +import io.temporal.activity.ActivityOptions; +import io.temporal.spring.boot.WorkflowImpl; +import io.temporal.workflow.Workflow; +import java.time.Duration; +import java.util.List; + +@WorkflowImpl(taskQueues = "CamelSampleTaskQueue") +public class OrderWorkflowImpl implements OrderWorkflow { + + private OrderActivity activity = + Workflow.newActivityStub( + OrderActivity.class, + ActivityOptions.newBuilder().setStartToCloseTimeout(Duration.ofSeconds(2)).build()); + + @Override + public List start() { + return activity.getOrders(); + } +} diff --git a/springboot/src/main/java/io/temporal/samples/springboot/camel/README.md b/springboot/src/main/java/io/temporal/samples/springboot/camel/README.md new file mode 100644 index 00000000..f2d374dc --- /dev/null +++ b/springboot/src/main/java/io/temporal/samples/springboot/camel/README.md @@ -0,0 +1,12 @@ +# SpringBoot Camel Sample + +1. Start SpringBoot from main samples repo directory: + + ./gradlew :springboot:bootRun + +2. In your browser navigate to: + + http://localhost:3030/orders + +This sample starts an Apache Camel route which runs our orders Workflow. +Results of the workflow are returned by the Camel route \ No newline at end of file diff --git a/springboot/src/main/resources/data.sql b/springboot/src/main/resources/data.sql index cd2d206c..607e95ae 100644 --- a/springboot/src/main/resources/data.sql +++ b/springboot/src/main/resources/data.sql @@ -2,4 +2,14 @@ INSERT INTO product(name, code, description, price, stock) VALUES ('Zoom U-Tale INSERT INTO product(name, code, description, price, stock) VALUES ('Yamamoto Baits 5" Senko', 'w2', 'Yamamoto Baits 5" Senko has become a mainstay for bass throughout the United States.', 7, 15); INSERT INTO product(name, code, description, price, stock) VALUES ('Rapala Original Floating Minnow', 'w3', 'The Rapala Original Floating Minnow is the lure that started it all and is still one of the most popular lures around.', 10, 10); INSERT INTO product(name, code, description, price, stock) VALUES ('Z-Man Jackhammer', 'w4', 'Exclusive patented ChatterBait bladed swim jig design and stainless hex-shaped ChatterBlade.', 18, 10); -INSERT INTO product(name, code, description, price, stock) VALUES ('Roboworm Straight Tail Worm Bait', 'w5', 'Roboworms are the most consistant poured baits on the market.', 9, 30); \ No newline at end of file +INSERT INTO product(name, code, description, price, stock) VALUES ('Roboworm Straight Tail Worm Bait', 'w5', 'Roboworms are the most consistant poured baits on the market.', 9, 30); + +INSERT INTO officeorder(number, date, desc, price) VALUES ('OR1', '1/02/2004', 'Office Chair', 120); +INSERT INTO officeorder(number, date, desc, price) VALUES ('OR2', '1/05/2004', 'Office Desk', 200); +INSERT INTO officeorder(number, date, desc, price) VALUES ('OR3', '1/05/2004', 'Computer Mouse', 30); +INSERT INTO officeorder(number, date, desc, price) VALUES ('OR4', '1/08/2004', 'Mouse Pad', 19); +INSERT INTO officeorder(number, date, desc, price) VALUES ('OR5', '1/10/2004', 'Office Sofa', 170); +INSERT INTO officeorder(number, date, desc, price) VALUES ('OR6', '1/12/2004', 'MacBook Air', 980); +INSERT INTO officeorder(number, date, desc, price) VALUES ('OR7', '1/12/2004', 'Pens', 9); +INSERT INTO officeorder(number, date, desc, price) VALUES ('OR8', '1/12/2004', 'Printer Paper', 22); +INSERT INTO officeorder(number, date, desc, price) VALUES ('OR9', '1/15/2004', 'Printer Cartridge', 110); \ No newline at end of file diff --git a/springboot/src/main/resources/templates/camel.html b/springboot/src/main/resources/templates/camel.html new file mode 100644 index 00000000..4c099ca5 --- /dev/null +++ b/springboot/src/main/resources/templates/camel.html @@ -0,0 +1,27 @@ + + + + +
+
+
+

Temporal Java SDK Samples

+
This sample shows how to start Workflow execution from an Apache Camel Route
+


+
+

Apache Camel is an integration framework + with a large number of out-of box integrations with many different apis. + In this sample we show how to integrate Temporal as part of a Camel Route which define steps + of messages from its source to destination. It allows you to bring numerous + advantages of Temporal such as high reliability and fault tolerance into your existing Camel applications. +

+

To run the sample navigate to localhost:3030/orders +
This endpoint starts a Camel Route which in turn starts our Workflow executipn and delivers results. +

+
+
+
+
+
+ + \ No newline at end of file diff --git a/springboot/src/main/resources/templates/index.html b/springboot/src/main/resources/templates/index.html index 6d074802..34df6ec1 100644 --- a/springboot/src/main/resources/templates/index.html +++ b/springboot/src/main/resources/templates/index.html @@ -22,6 +22,9 @@
Temporal Java SDK Samples
+ diff --git a/springboot/src/test/java/io/temporal/samples/springboot/CamelSampleTest.java b/springboot/src/test/java/io/temporal/samples/springboot/CamelSampleTest.java new file mode 100644 index 00000000..d751bc42 --- /dev/null +++ b/springboot/src/test/java/io/temporal/samples/springboot/CamelSampleTest.java @@ -0,0 +1,70 @@ +/* + * Copyright (c) 2020 Temporal Technologies, Inc. All Rights Reserved + * + * Copyright 2012-2016 Amazon.com, Inc. or its affiliates. All Rights Reserved. + * + * Modifications copyright (C) 2017 Uber Technologies, Inc. + * + * Licensed under the Apache License, Version 2.0 (the "License"). You may not + * use this file except in compliance with the License. A copy of the License is + * located at + * + * http://aws.amazon.com/apache2.0 + * + * or in the "license" file accompanying this file. This file 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.temporal.samples.springboot; + +import io.temporal.client.WorkflowClient; +import io.temporal.client.WorkflowOptions; +import io.temporal.samples.springboot.camel.OfficeOrder; +import io.temporal.samples.springboot.camel.OrderWorkflow; +import io.temporal.testing.TestWorkflowEnvironment; +import java.util.List; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInstance; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.boot.autoconfigure.EnableAutoConfiguration; +import org.springframework.boot.autoconfigure.kafka.KafkaAutoConfiguration; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.context.ConfigurableApplicationContext; +import org.springframework.test.context.ActiveProfiles; +import org.springframework.util.Assert; + +@SpringBootTest(classes = HelloSampleTest.Configuration.class) +@ActiveProfiles("test") +@TestInstance(TestInstance.Lifecycle.PER_CLASS) +// set this to omit setting up embedded kafka +@EnableAutoConfiguration(exclude = {KafkaAutoConfiguration.class}) +public class CamelSampleTest { + + @Autowired ConfigurableApplicationContext applicationContext; + + @Autowired TestWorkflowEnvironment testWorkflowEnvironment; + + @Autowired WorkflowClient workflowClient; + + @BeforeEach + void setUp() { + applicationContext.start(); + } + + @Test + public void testOrdersWorkflow() { + OrderWorkflow workflow = + workflowClient.newWorkflowStub( + OrderWorkflow.class, + WorkflowOptions.newBuilder() + .setTaskQueue("CamelSampleTaskQueue") + .setWorkflowId("CamelSampleWorkflow") + .build()); + List result = workflow.start(); + Assert.notNull(result, "Result should not be null"); + Assert.isTrue(result.size() == 9, "Invalid result"); + } +}