tenthe commented on issue #4139:
URL: https://github.com/apache/streampipes/issues/4139#issuecomment-3824458753

   Hi @intigration,
   thanks for reporting this.
   
   If I understand you correctly, you are trying to publish **two different 
kinds of events (with different event schemas) to the same topic**.
   
   This is **not directly supported in StreamPipes**. A StreamPipes adapter 
assumes that all incoming events conform to **one single event schema**.
   While it is possible to have *incomplete events* (i.e., some fields may be 
missing), it is **not possible to handle two completely different schemas 
within the same adapter**.
   
   ### Examples of different event schemas on the same topic
   
   **Example 1 – Temperature event**
   
   ```json
   {
     "deviceId": "sensor-1",
     "timestamp": 1700000000,
     "temperature": 21.5
   }
   ```
   
   **Example 2 – Status event**
   
   ```json
   {
     "deviceId": "sensor-1",
     "timestamp": 1700000005,
     "status": "offline"
   }
   ```
   
   Although both events might be sent to the same topic, they represent 
**different schemas** and therefore cannot be handled by a single adapter.
   
   If the schema of the events on a topic changes over time, the adapter must 
be **updated accordingly**.
   
   If you have **multiple different event schemas on one topic**, you can use 
the **new preprocessing functions** (currently available only in the **SNAPSHOT 
version**, but they will be part of the next release):
   
   * Create **one adapter per event schema**
   * Use preprocessing functions to **filter out events that do not match the 
expected schema**
   
   This way, each adapter only processes the events it is designed for.
   Here’s a simple and clear example you can use, plus a short description that 
fits nicely into your previous text.
   
   **Sample JavaScript filter function (status field)**
   
   This function forwards only those events that contain a `status` field. 
Events without this field are ignored.
   
   ```javascript
   // Forwards only events that contain a "status" field
   function transform(event, out, ctx) {
     if (event.status !== undefined && event.status !== null) {
       // returns the same event
       out.collect(event);
     }
   }
   ```
   
   Alternatively, if there are many different event types on one topic, you can 
leverage the **compact adapter API**, which allows you to avoid creating a 
large number of adapters manually via the UI.
   
   I hope this helps, let us know if you have further questions.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to