You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by "claudio4j (via GitHub)" <gi...@apache.org> on 2025/07/16 16:35:44 UTC
[PR] Kafka and SQL transactions quickstart [camel-spring-boot-examples]
claudio4j opened a new pull request, #163:
URL: https://github.com/apache/camel-spring-boot-examples/pull/163
(no comment)
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Kafka and SQL transactions quickstart [camel-spring-boot-examples]
Posted by "claudio4j (via GitHub)" <gi...@apache.org>.
claudio4j commented on code in PR #163:
URL: https://github.com/apache/camel-spring-boot-examples/pull/163#discussion_r2213816561
##########
kafka-sql-transaction/pom.xml:
##########
@@ -0,0 +1,136 @@
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.springboot.example</groupId>
+ <artifactId>examples</artifactId>
+ <version>4.14.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-example-spring-boot-kafka-sql-transaction</artifactId>
+ <name>Camel SB Examples :: Kafka :: SQL with transactions</name>
+ <description>An example of Kafka and SQL transactions.</description>
+
+ <properties>
+ <category>Messaging</category>
+ </properties>
+
+ <!-- Spring-Boot and Camel BOM -->
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring-boot-version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-spring-boot-bom</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <!-- Spring Boot -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-jdbc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-devtools</artifactId>
+ </dependency>
+
+ <!-- Camel -->
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-platform-http-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-kafka-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-sql-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jta</artifactId>
Review Comment:
removed, thanks.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Kafka and SQL transactions quickstart [camel-spring-boot-examples]
Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on code in PR #163:
URL: https://github.com/apache/camel-spring-boot-examples/pull/163#discussion_r2213728914
##########
kafka-sql-transaction/src/main/java/org/apache/camel/example/kafka/KafkaRoute.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.example.kafka;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.stereotype.Component;
+
+@Component
+public class KafkaRoute extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ String insert = "insert into foo(name) values (:#word)";
+
+ from("platform-http:/send/{word}")
+ .log("http word: ${header.word}")
+ .to("sql:" + insert)
+ .setBody(simple("{\"foo\": \"${header.word}\"}"))
+ .to("kafka:foo");
+
+ from("platform-http:/send2/{word}")
+ .log("http word: ${header.word}")
+ .setBody(simple("{\"foo\": \"${header.word}\"}"))
+ .to("kafka:foo")
+ .to("sql:" + insert);
+
+ from("platform-http:/sendtx/{word}")
+ .onException(Exception.class)
+ .handled(true)
+ .rollback("Expected error when trying to insert duplicate values in the unique column.")
+ .end()
+ .log("http word: ${header.word}")
+ .to("sql:" + insert)
Review Comment:
I do not think it is achievable.. and I am afraid the example is a little bit misleading, at least for me :D, do you think would it make more sense to remove the sql part? I think that something like
```
from("platform-http:...")
// some logic here
.to("kafka:..?transacted=true")
// more logic here
// and some exception thrown here
```
In this case the the kafka transaction will be rolledback
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Kafka and SQL transactions quickstart [camel-spring-boot-examples]
Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on code in PR #163:
URL: https://github.com/apache/camel-spring-boot-examples/pull/163#discussion_r2213632929
##########
kafka-sql-transaction/src/main/java/org/apache/camel/example/kafka/KafkaRoute.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.example.kafka;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.stereotype.Component;
+
+@Component
+public class KafkaRoute extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ String insert = "insert into foo(name) values (:#word)";
+
+ from("platform-http:/send/{word}")
+ .log("http word: ${header.word}")
+ .to("sql:" + insert)
+ .setBody(simple("{\"foo\": \"${header.word}\"}"))
+ .to("kafka:foo");
+
+ from("platform-http:/send2/{word}")
+ .log("http word: ${header.word}")
+ .setBody(simple("{\"foo\": \"${header.word}\"}"))
+ .to("kafka:foo")
+ .to("sql:" + insert);
+
+ from("platform-http:/sendtx/{word}")
+ .onException(Exception.class)
+ .handled(true)
+ .rollback("Expected error when trying to insert duplicate values in the unique column.")
+ .end()
+ .log("http word: ${header.word}")
+ .to("sql:" + insert)
Review Comment:
Maybe this is not achievable, but, what if this insert is executed, and exception is thrown during the `.to("kafka:foo?transacted=true")`? I do not think that the insert is rolledback because SQL and kafka are not part of the same transaction.... is it achievable somehow? I think that this use case would be interesting
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Kafka and SQL transactions quickstart [camel-spring-boot-examples]
Posted by "claudio4j (via GitHub)" <gi...@apache.org>.
claudio4j merged PR #163:
URL: https://github.com/apache/camel-spring-boot-examples/pull/163
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Kafka and SQL transactions quickstart [camel-spring-boot-examples]
Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on code in PR #163:
URL: https://github.com/apache/camel-spring-boot-examples/pull/163#discussion_r2213614040
##########
kafka-sql-transaction/pom.xml:
##########
@@ -0,0 +1,136 @@
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.springboot.example</groupId>
+ <artifactId>examples</artifactId>
+ <version>4.14.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-example-spring-boot-kafka-sql-transaction</artifactId>
+ <name>Camel SB Examples :: Kafka :: SQL with transactions</name>
+ <description>An example of Kafka and SQL transactions.</description>
+
+ <properties>
+ <category>Messaging</category>
+ </properties>
+
+ <!-- Spring-Boot and Camel BOM -->
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring-boot-version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-spring-boot-bom</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <!-- Spring Boot -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-jdbc</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-devtools</artifactId>
+ </dependency>
+
+ <!-- Camel -->
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-spring-boot-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-platform-http-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-kafka-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-sql-starter</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.camel</groupId>
+ <artifactId>camel-jta</artifactId>
Review Comment:
Given `NOTE: This example makes use of the local transaction manager in Kafka client and the JDBC driver, this is not a JTA managed transaction, given that kafka doesn't support a JTA transaction api.` is this dependency needed?
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Kafka and SQL transactions quickstart [camel-spring-boot-examples]
Posted by "Croway (via GitHub)" <gi...@apache.org>.
Croway commented on code in PR #163:
URL: https://github.com/apache/camel-spring-boot-examples/pull/163#discussion_r2213617536
##########
kafka-sql-transaction/pom.xml:
##########
@@ -0,0 +1,136 @@
+<!--
+
+ 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.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.camel.springboot.example</groupId>
+ <artifactId>examples</artifactId>
+ <version>4.14.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>camel-example-spring-boot-kafka-sql-transaction</artifactId>
+ <name>Camel SB Examples :: Kafka :: SQL with transactions</name>
+ <description>An example of Kafka and SQL transactions.</description>
+
+ <properties>
+ <category>Messaging</category>
+ </properties>
+
+ <!-- Spring-Boot and Camel BOM -->
+ <dependencyManagement>
+ <dependencies>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-dependencies</artifactId>
+ <version>${spring-boot-version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+
+ <dependency>
+ <groupId>org.apache.camel.springboot</groupId>
+ <artifactId>camel-spring-boot-bom</artifactId>
+ <version>${project.version}</version>
+ <type>pom</type>
+ <scope>import</scope>
+ </dependency>
+ </dependencies>
+ </dependencyManagement>
+
+ <dependencies>
+ <!-- Spring Boot -->
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-web</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.springframework.boot</groupId>
+ <artifactId>spring-boot-starter-jdbc</artifactId>
Review Comment:
LOL I spent some time understaing this, due to different format I thought it was an exclusion and I could not understand why it was needed, can you fix the format?
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] Kafka and SQL transactions quickstart [camel-spring-boot-examples]
Posted by "claudio4j (via GitHub)" <gi...@apache.org>.
claudio4j commented on code in PR #163:
URL: https://github.com/apache/camel-spring-boot-examples/pull/163#discussion_r2213800248
##########
kafka-sql-transaction/src/main/java/org/apache/camel/example/kafka/KafkaRoute.java:
##########
@@ -0,0 +1,61 @@
+/*
+ * 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.example.kafka;
+
+import org.apache.camel.builder.RouteBuilder;
+import org.springframework.stereotype.Component;
+
+@Component
+public class KafkaRoute extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ String insert = "insert into foo(name) values (:#word)";
+
+ from("platform-http:/send/{word}")
+ .log("http word: ${header.word}")
+ .to("sql:" + insert)
+ .setBody(simple("{\"foo\": \"${header.word}\"}"))
+ .to("kafka:foo");
+
+ from("platform-http:/send2/{word}")
+ .log("http word: ${header.word}")
+ .setBody(simple("{\"foo\": \"${header.word}\"}"))
+ .to("kafka:foo")
+ .to("sql:" + insert);
+
+ from("platform-http:/sendtx/{word}")
+ .onException(Exception.class)
+ .handled(true)
+ .rollback("Expected error when trying to insert duplicate values in the unique column.")
+ .end()
+ .log("http word: ${header.word}")
+ .to("sql:" + insert)
Review Comment:
> I do not think that the insert is rolledback because SQL and kafka are not part of the same transaction
correct. The quickstart is to show only the kafka transaction capability. The SQL part is there to throw an error and the route exchange is set to rollback the kafka delivery. I will enhance this information in the description.
--
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: commits-unsubscribe@camel.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org