Cutting through the clutter: Notification 2.0 Sample

Notification 2.0 API with a Practical Microservice Example

Introduction

After exploring the Notification 2.0 API in 2023, several insights have emerged:

The Notification API is relatively new and therefore lacks an abundance of examples illustrating practical applications. Additionally, the API introduces complexities that may pose challenges for new developers seeking optimal usage. In response, PS has developed a new example rooted in real-world N2.0 use cases. This example aims to showcase best practices for effectively utilizing the API while steering clear of common pitfalls that developers may encounter.

In particular, Professional Services (PS) consultants seek a comprehensive example that allows them to seamlessly integrate code and concentrate on their business logic. The desire is to sidestep the complexities of WebSocket connection management, multitenancy, reconnects, and cleanup. To address this, we have contributed sample code to a Git repository, and the subsequent section outlines its key features. I trust that this resource proves beneficial. Don’t hesitate to reach out if you envision additional features or have suggestions for enhancements. Your feedback is greatly appreciated.

The Notification-2-Sample-MS repository offers a practical demonstration of a microservice leveraging the Notification 2.0 API. This example delves into various aspects of the API, shedding light on common scenarios encountered by developers.
Here is the link to the github repository: SoftwareAG/Notification-2-Sample: This repository contains a practical example of a microservice utilizing the Notification 2.0 API. (github.com)

Key Features

1. Device Subscriptions

  • Subscription to a device in managed object context.
  • Subscription in tenant context.
  • Example of subscribing for measurements.

2. General Subscriptions

  • Subscription to all devices.

3. Disconnect Management

  • Handling disconnects and reconnect logic.
  • Posting an alarm directly on the microservice if a disconnect is detected.

4. Multitenancy Support

  • Demonstrates support for deployment on the management tenant, with multiple subtenants subscribing to it.

Important Considerations

For Notification 2.0 API

  1. Unsubscribe Subscribers

    • It’s crucial to unsubscribe a subscriber if it’s no longer needed to prevent storage issues caused by continuous notifications.
  2. Disconnect Handling

    • The microservice includes logic to raise a critical alarm upon disconnect detection and clear the alarm once reconnected.
  3. Reconnect Challenges

    • Immediate reconnection attempts may lead to a 409 Conflict error. The example retries with a delay to avoid this issue.
  4. Explicit Management of WebSocket Connection State

    • The example manages the WebSocket connection state explicitly.
  5. WebSocket Library Consideration

    • Explore WebSocket libraries like tooTallNate for automatic reconnects.
  6. Subscribing to All Devices

    • While generally not recommended, the sample demonstrates how it can be achieved, recognizing its frequent need.
  7. Multitenancy Implementation

    • For actual deployment, consider enhancing the code through multi-threading, utilizing multiple threads and shared resources.

Assumption

This microservice assumes that it subscribes to all devices and maintains an open connection indefinitely.

Disclaimer

These tools are provided as-is, without warranty or support, and do not constitute part of the Software AG product suite. Users are free to use, fork, and modify them, subject to the license agreement. While Software AG welcomes contributions, inclusion in the master project cannot be guaranteed. Refer to the documentation for more information.



Arsalan Mahmood Siddiqi

3 Likes