Async spring boot and Certifications journey

I have two updates in this blog post. For my lack of consistency in not blogging, I had to revisit this.

“Getting an audience is hard. Sustaining an audience is hard. It demands a consistency of thought, of purpose, and of action over a long period of time.”

– Bruce Springsteen.

When I was gone, here are a few things I was able to wrap up. Blogging with all this going on was not something I could stretch out.

  • AWS certification
  • 3 Azure certifications
  • HashiCorp certification
  • Java 19 virtual threads- project loom (This is awesome)
  • Lost around $100 of Azure credits for not shutting down the resource groups I started.

A few things that worked out well for my certifications were the side gigs I was able to get done for my Indie clients. For preparing the certs, acloud.guru was the best. But I loved Microsoft’s documentation for the certification path, and I felt it was far better than the AWS certifications and the direction it laid out.

Here is a quick tweak I wanted to blog about with Spring boot and its API power. Here is a scenario, suppose when you need to kick off an asynchronous application call in spring boot, and the framework’s in-built annotation support is convenient.

The main application publishes an event to kick off an async send email event.

Spring boot framework works on the publish and subscribe event model. For posting an event, one will annotate the spring bean with event publisher annotation. Here is a sample code.


@Service

@RequiredArgsConstructor
public class JobApplicationService {
    private final JobApplicationRepository jobApplicationRepository;
    private final ApplicationEventPublisher publisher;

    @Transactional(readOnly = true)
    public List<JobApplication> getAllAppliedJobs() {
        return jobApplicationRepository.findAll();
    }

    @Transactional
    public JobApplication createJobApplicationRecord(JobApplication road) {
        jobApplicationRepository.save(road);
        publisher.publishEvent(new JobAppliedEvent(road));
        return road;
    }

    @Transactional
    public JobApplication getJobApplicationByID(Long id) {
        return jobApplicationRepository.findById(id)
                .orElseThrow(() -> new JobApplicationDataException(id));
    }
}

In the code block above the line item, ApplicationPublisher class tells the framework that this service will generate events.

Now you will need a subscriber to listen to this event and do its async processing.

import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import org.springframework.transaction.event.TransactionalEventListener;

@Component
@RequiredArgsConstructor
public class KnowledgeListener {
    private final KowledgeService knowledgeService;

    @TransactionalEventListener
    public void onRegisterEvent(JobAppliedEvent event) {
        knowledgeService.sendRoadRegisteredKnowledge(event.getJobApplication());
    }

    @EventListener
    public void onCustomerRemovedEvent(JobAppliedEvent event) {
        knowledgeService.sendRoadRemovedKnowledge(event.getJobApplication());
    }
}

The annotation @TransactionalEventListener is the one that this going to be indicating the framework that the class and its methods are going to listen to the publish and do the task as requested in the listener block.

This publisher/subscriber model from the boot is powerful and valuable for the applications that will need async processing and would want spring boot to help them with guardrails.

Github URL for the project