Atlassian Events is a library that allows other plugins to send and consume internal messages within Atlassian applications.
It provides a framework for creating, publishing, and listening to custom events. This is useful for developers who want to extend
the functionality of Atlassian products by reacting to specific events or changes within the system.
This page helps developers setup the Event Listener and Event Publisher.
Event Listener is a component that listens for specific events occurring within Atlassian applications and performs actions in response to those events.
Event Publisher is a component responsible for publishing events within the Atlassian ecosystem.
It acts as a central mechanism to broadcast events to any registered listeners that are interested in those events.
1 2<dependency> <groupId>com.atlassian.event</groupId> <artifactId>atlassian-event</artifactId> <scope>provided</scope> </dependency>
An event can be a simple POJO with fields that must define their access methods, for example:
1 2public class UsernameChangedEvent { private final String oldUsername; private User newUser; public UsernameChangedEvent(String oldUsername, User newUser) { this.oldUserName = oldUsername; this.newUser = newUser; } public String getOldUsername() { return oldUsername; } public User getNewUser() { return newUser; } }
This class should be public API. Plugins that listen to this event will have to import the event's java class.
To publish an event, you need to inject the EventPublisher
into your class and use it to publish your custom event.
It can be an already existing class or you can create a custom class dedicated to publishing events:
1 2public class UsernameChangedEventPublisher { private final EventPublisher eventPublisher; public UserManager(EventPublisher eventPublisher) { this.eventPublisher = eventPublisher; } public void publishUsernameChangedEvent(User newUser, String oldUsername) { // Publish the event eventPublisher.publish(new UsernameChangedEvent(oldUsername, newUser)); } }
To create an event listener, follow these steps:
EventPublisher
into your listener class.@EventListener
annotation on methods that should handle events.
1 2public class UsernameChangedEventListener implements InitializingBean, DisposableBean { private final EventPublisher eventPublisher; public DefaultCalendarNotificationManager(EventPublisher eventPublisher) { this.eventPublisher = eventPublisher; } @Override public void afterPropertiesSet() throws Exception { // Register with the EventPublisher eventPublisher.register(this); } @Override public void destroy() throws Exception { // Unregister from the EventPublisher eventPublisher.unregister(this); } @EventListener public void onUsernameChanged(UsernameChangedEvent event) { // Handle the event } }
For the configuration you have to do 3 things:
atlassian-plugin.xml
<listener key="eventListener" class="com.example.tutorial.plugins.IssueCreatedResolvedListener"/>
EventPublisher
bean, read spring Java Config page to learn how to import beans using spring-java-config.@AsynchronousPreferred
.
This annotation leverages java.util.concurrent.Executor
to run each event in its own thread, handling them
through thread queues for efficient management.
You can add this annotation to your event POJO like so:
1 2@AsynchronousPreferred public class UsernameChangedEvent { ... }
Rate this page: