Implementing Custom Logic and External Integrations
While Liferay provides built-in object actions for implementing custom business logic, more advanced use cases often require extending these capabilities and integrating with external services. To achieve this, Liferay offers these options:
-
Webhook Action: Push data to external systems in real-time.
-
Object Action Client Extension: Execute custom logic in external microservices.
-
Groovy Script Action: Implement custom logic within Liferay's scripting environment (available for Liferay PaaS and Self-Hosted).
Together, these features extend Liferay’s default functionality and enable you to perform more complex logic and trigger actions in external systems. However, each approach has unique considerations regarding performance and maintainability. So it's essential to plan ahead and determine the most suitable strategy for your specific use case and deployment environment.
Webhook Actions
Webhooks enable real-time data integration with external systems by sending JSON payloads to a specified URL. This enables you to push object data from Liferay to other applications whenever action triggers and conditions are met. For enhanced security, webhooks support an optional secret key for request verification.
Here are some example use cases:
-
Real-time Reporting: Push object data to Google Sheets for live reporting and analysis.
-
Inventory Management: Update an external inventory system when product entries are created or modified in Liferay.
-
Third Party Processing: Deliver object data to third-party services for processing.
Webhook use cases can vary from simply delivering data to an external service for storage to triggering complex processing workflows. However, when using webhooks for processing, it's essential to consider potential performance implications and design your integration strategically to avoid creating dependencies that could lead to bottlenecks or delays.
Object Action Client Extensions
The Object Action client extensions define custom actions that you can add to object definitions. They define external action handlers that execute custom logic through external microservices according to the action’s trigger and conditions. By supporting OAuth2, these client extensions are suitable for integrations requiring detailed permissions and authorization.
Here are some example use cases:
-
Custom Calculations: Perform advanced calculations on object data.
-
CRM Integration: Update customer records in an external CRM system based on object data changes in Liferay.
-
ERP or OMS Integration: Send updated product orders to an ERP (Enterprise Resource Planning) or OMS (Order Management System) after state changes.
Action client extensions execute outside of Liferay, so they offer some advantages, including flexibility, improved scalability, and the ability to implement complex logic using third-party tools. However, to avoid performance bottlenecks in high-demand environments, they require strategic design and careful consideration of potential architectural issues.
Groovy Script Actions
Groovy scripts leverage Liferay DXP's scripting engine to execute custom logic within the Liferay service. This provides direct access to Liferay's service layer and utilities, simplifying interaction with Liferay's data and functionality. Example use cases include many covered by action client extensions, though Groovy actions are especially geared towards interacting with Liferay's features and data programmatically.
Groovy actions execute within Liferay's JVM, granting them unrestricted access to Liferay's services and data. While convenient for certain tasks, this access elevates the risk of unintended consequences, such as exposing sensitive information, data corruption, or performance degradation. Therefore, Groovy actions are not recommended as a general best practice. As of DXP 2024.Q3, scripting is disabled by default and requires explicit activation in system settings. Access to Groovy actions should be limited to portal administrators.
Benefits of Webhook and Client Extension Actions
Using webhook and client extensions to connect with external services can provide significant benefits, including:
-
Flexible Integration: Enhance interoperability and data sharing across platforms.
-
Enhanced Security: Secure communication through secret keys (webhook) or OAuth2 (client extension).
-
Improved Scalability: Reduce load on Liferay by offloading complex processing to external services.
-
Data Synchronization: Synchronize data across connected systems to ensure consistency.
-
Simplified Development and Maintenance: Streamline development, reduce complexity, and improve maintainability by protecting against breaking changes.
-
Lower Cost of Ownership: Use any programming language or technology without relying on specialized Liferay expertise.
Webhooks or Client Extensions?
Choosing between webhook and client extension actions depends on several factors, including your security requirements, needed control over external access, and specific integration needs. While both offer valuable capabilities, Client Extensions are generally preferred for most integrations due to their enhanced security, flexibility, and performance at scale.
When to Use Client Extension Actions
Client extension actions provide stronger security and control than webhook actions. This is because of their support for OAuth2, granular access control, and complex logic. OAuth2 enables strict access control, enabling you to specify precisely which external services can access your Liferay data. With granular access control, they also empower you to fine-tune the actions each microservice can perform within Liferay. Developed with your preferred programming language, client extensions offer high flexibility and are ideal for complex logic or integrations requiring advanced calculations or third-party interactions.
Typical Use Cases
-
Enterprise System Integration: Integrating with CRM or ERP systems where sensitive data and strong authentication are essential.
-
Data Processing: Handling data-intensive tasks that require secure and controlled access.
-
Microservice Architectures: Managing integrations with multiple microservices that require varying levels of access.
When to Use Webhook Actions
Webhooks might be suitable for simpler integrations or situations where OAuth2 authentication is not feasible. However, use them judiciously to avoid potential performance bottlenecks, especially in high-traffic environments.
Typical Use Cases
-
Simple Notifications: Sending alerts or real-time notifications to external applications, such as Slack or email systems.
-
Lightweight Data Pushes: Transferring data without complex security requirements or extensive processing.
Using These Actions for Clarity’s Apps
Clarity's distributor management app can leverage webhook and client extension actions to automate and enhance the onboarding process. For example, a client extension (or webhook) could send application data to an external system for verification. Upon successful verification, the external system could update the application’s status in Liferay, ensuring real-time synchronization. Additionally, a client extension could securely invoke a CRM microservice to create a new distributor account, using OAuth2 to securely maintain data consistency between Liferay and the CRM.
Best Practices for Using These Actions Effectively
Webhook and client extension actions offer powerful capabilities for extending Liferay’s default functionality. However, to ensure optimal performance, security, and maintainability, it's essential to consider the following best practices.
Designing Efficient Data Models
When designing solutions with Liferay Objects, prioritize minimizing REST calls. A common pitfall is over-reliance on traditional database modeling, leading to numerous small objects. This results in excessive REST calls and performance issues. These practices can help optimize performance:
-
Favor Denormalization: Create larger, denormalized objects that consolidate fields whenever possible. Introduce new objects only when necessary for relationships. This reduces REST calls and improves performance.
-
Avoid Over-Segmentation: Avoid segmenting data into multiple objects unless absolutely necessary. Each additional object increases the volume of REST calls, degrading performance, particularly in high-load or complex solutions.
-
Prioritize Scalability: Consider performance from the outset of your design process to avoid costly rework later. Involve an architecture review early on to identify potential performance bottlenecks.
Proactive data model design can prevent costly and time-intensive rework later in the development process.
Secure Communication
Security is paramount when integrating with external systems. For webhook actions, use the optional secret key to secure communication and verify the authenticity of requests. This helps prevent unauthorized access to your Liferay data. For client extension actions, implement OAuth2 authentication securely, following recommended practices for token handling and authorization. This ensures that only authorized external services can access and interact with your Liferay data and functionality.
Optimize Triggers
Avoid triggering webhook and client extension actions for every minor update to object entries. Instead, focus on triggering these actions only for meaningful events that require external interaction or processing. This reduces unnecessary load on both your Liferay instance and the external systems involved.
Optimize Processing
When using webhooks or client extensions, consider these strategies to optimize processing and maintain performance:
-
Use Batch Processing: For actions affecting large datasets, use batch processing whenever possible. This approach helps limit the number of REST calls and reduces the performance impact on Liferay.
-
Prioritize Asynchronous Processing: For client extensions that interact with external services or perform time-consuming operations, prioritize asynchronous processing. This prevents the client extension from being blocked while waiting for external responses, ensuring responsiveness and preventing potential bottlenecks, especially under heavy user load.
When first developing your solution, consider how external services might impact performance. For example, if a client extension relies on an external service for data enrichment or validation, ensure that the service is responsive and reliable. Delays or failures in the external service can negatively impact the performance of your Liferay application, especially if these calls are synchronous.
Conclusion
Liferay's webhook, client extension, and Groovy actions offer powerful options for implementing custom logic and integrating with external services. By adhering to best practices, you can leverage these actions effectively, creating robust, secure, and scalable integrations that enhance your Liferay DXP solutions.
Capabilities
Product
Education
Contact Us