What is SEDA and How to implement SEDA usingApache Camel ? | Software Architecture Pattern

Jasvinder S Saggu
2 min readJul 3, 2021

--

  • The SEDA component provides asynchronous SEDA behaviour
  • Messages are exchanged on a BlockingQueue and consumers are invoked in a separate thread from the producer
  • Queues are only visible within a single CamelContext
  • This component does not implement any kind of persistence or recover
  • URI Format
  • seda:some-name?options

pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.4.7</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.jss</groupId>
<artifactId>camel</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>camel</name>
<description>Apache Camel with Spring Boot</description>

<properties>
<java.version>1.8</java.version>
<junit.platform.version>1.6.0</junit.platform.version>
<camel.version>3.7.3</camel.version>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.camel.springboot</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>${camel.version}</version>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test</artifactId>
<scope>test</scope>
<version>${camel.version}</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-rabbitmq</artifactId>
<version>${camel.version}</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jackson</artifactId>
<version>${camel.version}</version>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-jaxb</artifactId>
<version>${camel.version}</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
<version>1.18.12</version>
</dependency>

<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-runner</artifactId>
<version>${junit.platform.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<version>5.7.0</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-junit5</artifactId>
<version>${camel.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring-junit5</artifactId>
<version>${camel.version}</version>
<scope>test</scope>
</dependency>

</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>

CamelApplication.java

package com.jss.camel;

import org.apache.camel.ProducerTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.concurrent.TimeUnit;

@SpringBootApplication
public class CamelApplication {
@Autowired
ProducerTemplate producerTemplate;

public static void main(String[] args) throws InterruptedException {
SpringApplication.run(CamelApplication.class, args);
TimeUnit.SECONDS.sleep(20);
}
}

SedaRoute.java

package com.jss.camel.components;

import org.apache.camel.Message;
import org.apache.camel.builder.RouteBuilder;
import org.apache.camel.support.DefaultMessage;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.stereotype.Component;

import java.util.Date;

import static java.util.concurrent.TimeUnit.SECONDS;
import static org.apache.camel.LoggingLevel.ERROR;

@Component
@ConditionalOnProperty(name = "jss.camel.seda.enabled", havingValue = "true", matchIfMissing = true)
public class SedaRoute extends RouteBuilder {
@Override
public void configure() {
from("timer:ping?period=200")
.process(exchange -> {
Message message = new DefaultMessage(exchange);
message.setBody(new Date());
exchange.setMessage(message);
})
.to("seda:weightLifter?multipleConsumers=true");

from("seda:weightLifter?multipleConsumers=true")
.to("direct:complexProcess");

from("direct:complexProcess")
.log(ERROR, "${body}")
.process(exchange -> SECONDS.sleep(2))
.end();
}
}

--

--

No responses yet