Auf JMS is aimed at Spring-based applications that need to implement a messaging archiecture on top of JMS brokers. It offers an annotation-driven and declarative programming model that abstracts away low-level JMS API's by offering a set of annotations and conventions with which application developers declare the intentions via plain Java classes and provided annotations.
Assuming you have a Spring Boot application ready, add dependency:
Enable by @EnableByJms
.
@EnableByJms
@SpringBootApplication
class ClientApplication {
public static void main(final String[] args) {
SpringApplication.run(ClientApplication.class, args);
}
}
Declare by @ByJms
.
@ByJms(@To("${app.task.inbox}"))
public interface TaskInbox {
void runJob(Job job);
}
At this point, you have a JMS client proxy that when invoked will send a message
- to a queue named by Spring property
app.task.inbox
- with the message type of
RunJob
- with the message body of
job
serialized in JSON
The proxy won't do anything by itself, so the next step is to...
Inject and enjoy.
@Service
public class AppService {
// Do something with it
@Autowired
private TaskInbox taskInbox;
...
}
To send to a topic
@ByJms(@To(value = "${app.task.status}", type = DestinationType.TOPIC))
public interface TaskStatus {
void updateJobStatus(@OfProperty String jobId, Status status);
}
Enable by @EnableForJms
.
@EnableForJms(value = @Inbound(@From("${app.task.inbox}")))
@SpringBootApplication
class ServerApplication {
public static void main(final String[] args) {
SpringApplication.run(ClientApplication.class, args);
}
}
Implement business logic by JMS type
@ForJmsType
class RunJob {
public void invoke(Job job) {
//Do the work
}
}
The latest major version 3 requires the following to run:
- JDK 21
- JMS 3.1
- Spring Framework 6.1
- Jackson 2: Core and Databind
In addition to the above, the server-side features provided by @EnableForJms
requires:
The release binaries can be found on Maven Central.
The version 2 releases are on JDK 17, JMS 3.1, Spring 6.
The version 1 releases are on JMS 2.0 and Spring 5.