Initialize project with ActiveQM Client
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-activemq</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
Enable JMS configuration
@Configuration
@EnableJms
public class IntegrationConfiguration {
}
Add integration layer controller
@Component
public class EmployeeJms {
@Autowired
private EmployeeService service;
@JmsListener(destination = "employee-info-request")
@SendTo("employee-info-response")
public String getDepartment(String employeeId) {
return service.getDepartment(employeeId);
}
}
Simulation for business
@Service
public class EmployeeService {
private static final Logger LOGGER = LoggerFactory
.getLogger(EmployeeService.class);
public String getDepartment(String employeeId) {
LOGGER.info("Begin get department info of employee [{}]", employeeId);
simulateQuery(employeeId, 3);
LOGGER.info("End get department info of employee [{}]", employeeId);
return "Technology";
}
private void simulateQuery(String employeeId, int processTime) {
try {
TimeUnit.SECONDS.sleep(processTime);
}
catch (InterruptedException e) {
}
}
}
Configure to point to Message Broker
spring:
application:
name: spring-jms
profiles.active: default
activemq:
in-memory: false
broker-url: tcp://activemq-dev:61616
user: admin
password: admin
jms:
listener:
auto-startup: true
concurrency: 3
max-concurrency: 3
10.853581
106.625434
Like this:
Like Loading...