DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Refcards Trend Reports
Events Video Library
Over 2 million developers have joined DZone. Join Today! Thanks for visiting DZone today,
Edit Profile Manage Email Subscriptions Moderation Admin Console How to Post to DZone Article Submission Guidelines
View Profile
Sign Out
Refcards
Trend Reports
Events
View Events Video Library
Zones
Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Integrating PostgreSQL Databases with ANF: Join this workshop to learn how to create a PostgreSQL server using Instaclustr’s managed service

Mobile Database Essentials: Assess data needs, storage requirements, and more when leveraging databases for cloud and edge applications.

Monitoring and Observability for LLMs: Datadog and Google Cloud discuss how to achieve optimal AI model performance.

Automated Testing: The latest on architecture, TDD, and the benefits of AI and low-code tools.

Related

  • Perform Remote Caches With JBoss Fuse and Red Hat Data Grid
  • Building a Real-Time Alerting Solution With Zero Code
  • Building an Event-Driven Architecture Using Kafka
  • What Are Events? Process, Data, and Application Integrators

Trending

  • The Ultimate Guide to API vs. SDK: What’s the Difference and How To Use Them
  • Modular Software Architecture: Advantages and Disadvantages of Using Monolith, Microservices and Modular Monolith
  • Harnessing the Power of In-Memory Databases: Unleashing Real-Time Data Processing
  • Top 7 Best Practices DevSecOps Team Must Implement in the CI/CD Process
  1. DZone
  2. Data Engineering
  3. Big Data
  4. Scalable Events With JBoss Data Grid Pt. 1

Scalable Events With JBoss Data Grid Pt. 1

JBoss Data Grid is loaded with handy features. Learn more about its scalable events capabilities.

Thomas Qvarnström user avatar by
Thomas Qvarnström
·
Sep. 25, 15 · Tutorial
Like (4)
Save
Tweet
Share
2.86K Views

Join the DZone community and get the full member experience.

Join For Free

JBoss Data Grid is not only a scalable in-memory data grid, but also have a ot of powerful features that are useful in different scenarios beyond storing data. In this series or article we will look closer Scalable Events which has multiple practical use-cases. We will see how events in data grid can be used to scale websocket or how is can be used in a event based integration scenario. First we will start with an overview event listeners in JBoss Data Grid.

Overview of Listeners

JBoss Data Grid has two main types of listeners, one is used when the data grid is running embedded with the application (also called library mode) and are simple called event listeners. The other type is used when the data grid is running in a separate process from the application (also called remote mode) and are called remote event listeners. 

One mayor difference between database triggers and remote event listeners is that in the later alternative the arbitrary code is executed on the client side instead of inside the database. 

Remote Event Listeners

Remote event listeners is a Hot Rod feature, meaning that it's designed to be used in Client/Server mode where the data grid is running in a separate process from the client. There are however also listeners in the embedded mode, but for the sake of clarity we will only focus on Remote Listeners for the reminder of this article.

The following events are supported in the Hot Rod Client:

  • Cache entry created
  • Cache entry modified
  • Cache entry removed

Creating an event listener is quite simple and only requires two steps:

    Create a Client Event Listener class

    package ...;
    
    import org.infinispan.client.hotrod.annotation.ClientCacheEntryCreated;
    import org.infinispan.client.hotrod.annotation.ClientListener;
    import org.infinispan.client.hotrod.event.ClientCacheEntryCreatedEvent;
    import org.jboss.logging.Logger;
    
    
    @ClientListener
    public class MessageListener {
    
     private Logger logger = ...
    
     @ClientCacheEntryCreated
     public void handleCreated(ClientCacheEntryCreatedEvent<String> e) {
      logger.info(String.format("Received Cache Event of type %s with key %s", e.getType().toString(), e.getKey()));
    
     }
    
    
    }

    Register your event listeners with the cache,

private MessageListener messageListener;

@Inject @MessageCache
RemoteCache<String,Message> mc;

@PostConstruct
public void init() {
messageListener = new MessageListener(); 
mc.addClientListener(messageListener);

}

@PreDestroy
public void destroy() {
mc.removeClientListener(messageListener); 
mc.stop();

}

Every time this or another client to the data grid stores a new entry (i.e. using put or putIfAbsent) the MessageListener will be executed and print the log statement. 

Filtering Events

If the expected workload favors writes over reads it may be necessary to filter the events sent to the clients to prevent a large amount of excessive traffic being generated. We will cover how to filter event in a later article, but since filters are execute on the server it side it does mean that we have to deploy logic to the data grid server.


Customizing Remote Events

For performance reasons events default only contains the key and the type of event  (created, modified or removed). However if all events consumed will make use of the value it it might be more efficient to also include the value of the event. Be aware that the custom event has a bigger event payload compared with default events.

In the next part we will look closer at example use-cases where scalable events can be used.

Event Data grid Data (computing) JBoss

Published at DZone with permission of Thomas Qvarnström, DZone MVB. See the original article here.

Opinions expressed by DZone contributors are their own.

Related

  • Perform Remote Caches With JBoss Fuse and Red Hat Data Grid
  • Building a Real-Time Alerting Solution With Zero Code
  • Building an Event-Driven Architecture Using Kafka
  • What Are Events? Process, Data, and Application Integrators

Comments

Partner Resources

X

ABOUT US

  • About DZone
  • Send feedback
  • Careers
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends: