To use the shared podzilla-utils-lib in your microservice project, add it as a dependency in your project's pom.xml.
This library is hosted on JitPack, so you also need to add the JitPack repository URL to your pom.xml.
Add the following <repositories> section to your microservice's pom.xml (under the main <project> element or inside an existing <repositories> section):
<repositories>
<repository>
<id>jitpack.io</id>
<url>https://jitpack.io</url>
</repository>
</repositories>Inside your <dependencies> section, add:
<dependency>
<groupId>com.github.Podzilla</groupId>
<artifactId>podzilla-utils-lib</artifactId>
<version>v1.1.6</version>
</dependency>Once added, build your project using:
mvn clean install -U🧠 The
-Uflag forces Maven to update all snapshots/releases, ensuring it downloads the latest version from JitPack.
Configure your application to connect to RabbitMQ by adding these properties to your src/main/resources/application.properties:
# RabbitMQ Configuration
spring.rabbitmq.host=rabbitmq
spring.rabbitmq.port=5672
spring.rabbitmq.username=guest
spring.rabbitmq.password=guestNote on RabbitMQ Host:
spring.rabbitmq.host=rabbitmqassumes your app and RabbitMQ are on the same Docker network.- If RabbitMQ is on your Docker host (e.g., with Docker Desktop), use
spring.rabbitmq.host=host.docker.internal. - Otherwise, use the specific IP address or resolvable hostname.
To ensure Spring discovers the library components, include com.podzilla in @ComponentScan. If your service uses a different base package, include that as well:
@SpringBootApplication
@ComponentScan(basePackages = { "com.podzilla", "com.yourcompany.myservice" }) // Add your service package if different
public class MyApplication {
public static void main(String[] args) {
SpringApplication.run(MyApplication.class, args);
}
}Replace "com.yourcompany.myservice" with your actual service package if it's different from com.podzilla.
Publish events using the EventPublisher component from the library.
Injecting the Publisher:
@Service
@RequiredArgsConstructor
public class MyService {
private final EventPublisher eventPublisher;
// ... your service methods
}Event Metadata & Payload:
Use EventMetadata constants from EventsConstants (e.g., COURIER_REGISTERED). Event payloads are classes extending BaseEvent (e.g., CourierRegisteredEvent).
EventsConstants.COURIER_REGISTERED→CourierRegisteredEventEventsConstants.ORDER_PLACED→OrderPlacedEventEventsConstants.INVENTORY_UPDATED→InventoryUpdatedEventEventsConstants.ORDER_DELIVERED→OrderDeliveredEvent
Example of Publishing:
@Service
@RequiredArgsConstructor
public class MyService {
private final EventPublisher eventPublisher;
public void registerCourier(CourierRegisteredEvent payload) {
eventPublisher.publishEvent(EventsConstants.COURIER_REGISTERED, payload);
}
}Each service can define up to three queues—one for each exchange: user, order, and inventory. These queues receive different event types, but all events extend BaseEvent from the shared library.
When consuming, use the @RabbitListener annotation. You can inspect the specific event type using instanceof or reflection.
Queue Constants
Queue names are defined in EventsConstants using the format:
<SERVICE>_<EXCHANGE>_EVENT_QUEUE
Examples:
ANALYTICS_USER_EVENT_QUEUEORDER_ORDER_EVENT_QUEUEWAREHOUSE_INVENTORY_EVENT_QUEUECOURIER_USER_EVENT_QUEUE
Example Listener:
@Component
public class AnalyticsUserEventsConsumer {
@RabbitListener(queues = EventsConstants.ANALYTICS_USER_EVENT_QUEUE)
public void handleEvent(BaseEvent event) {
if (event instanceof CourierRegisteredEvent) {
CourierRegisteredEvent courierEvent = (CourierRegisteredEvent) event;
System.out.println("Received Courier Registered Event: " + courierEvent);
// Add your business logic here
}
}
}The QueueResolver utility helps during local development by determining which queue a service should listen to for a given event.
⚠️ Note: This utility is not used at runtime in production. It is designed for test scaffolding, dev tooling, or simulating behavior in local environments.
Usage:
String queue = QueueResolver.getQueueForServiceEvent(
EventsConstants.SERVICE_ANALYTICS,
EventsConstants.ORDER_PLACED
);
System.out.println("Queue to listen on: " + queue);
// Output: "ANALYTICS_ORDER_EVENT_QUEUE"Signature:
public static String getQueueForServiceEvent(String serviceName, EventsConstants.EventMetadata eventMetadata)serviceName: e.g.,EventsConstants.SERVICE_ANALYTICSeventMetadata: e.g.,EventsConstants.ORDER_PLACED- Returns the appropriate queue name string, or
nullif no match is found.
-
The stable code lives in the
mainbranch. -
When ready to release a new version:
-
Update the version in
pom.xml(remove-SNAPSHOT, set new version). -
Commit the version change.
-
Create a Git tag with the version number, e.g.:
git tag -a vX.Y.Z -m "Release version X.Y.Z" -
Push the changes and the tags:
git push origin main git push origin --tags
-
-
Note: Pushing the tag automatically triggers the build and deployment on JitPack.
-
Check the build status on GitHub Actions and your release on JitPack.