-
Notifications
You must be signed in to change notification settings - Fork 151
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
SpringBoot - Apache Camel Sample #581
Merged
+534
−3
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 55 additions & 0 deletions
55
springboot/src/main/java/io/temporal/samples/springboot/camel/CamelConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
springboot/src/main/java/io/temporal/samples/springboot/camel/CamelResource.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<OfficeOrder> getProductsByCategory() { | ||
producerTemplate.start(); | ||
List<OfficeOrder> orders = producerTemplate.requestBody("direct:getOrders", null, List.class); | ||
producerTemplate.stop(); | ||
return orders; | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
springboot/src/main/java/io/temporal/samples/springboot/camel/CamelRoutes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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(); | ||
} | ||
} |
92 changes: 92 additions & 0 deletions
92
springboot/src/main/java/io/temporal/samples/springboot/camel/OfficeOrder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
springboot/src/main/java/io/temporal/samples/springboot/camel/OrderActivity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<OfficeOrder> getOrders(); | ||
} |
37 changes: 37 additions & 0 deletions
37
springboot/src/main/java/io/temporal/samples/springboot/camel/OrderActivityImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<OfficeOrder> getOrders() { | ||
return repository.findAll(); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
springboot/src/main/java/io/temporal/samples/springboot/camel/OrderRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<OfficeOrder, Integer> {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Any reason you used
3.22.1
vs4.x
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
4.x requires java 17 or higher