siddhisendasynchronousrequestwso2-streaming-integrator

Syntax error in SiddhiQL, no viable alternative at input '@sink'


I'm trying to send a synchronous request using http-request (source) and http-response (sink) in Siddhi based on an example here.

I have an API, which I'm able to hit using a curl command. This is my curl command and the output.

curl http://localhost/parser/ -d '{"q":"test input", "project":"sample_project","model":"sample_model"}'
{
  "intent": {
    "name": "Cat A",
    "confidence": 0.7
  },
  "entities": [],
  "intent_ranking": [
    {
      "name": "Cat A",
      "confidence": 0.7
    },
    {
      "name": "Cat B",
      "confidence": 0.6
    },
    {
      "name": "Cat C",
      "confidence": 0.01
  ],
  "text": "test input",
  "project": "sample_project",
  "model": "sample_model"
}

I'm trying to do something similar using Siddhi.

This is my code.

@source(type='http-request', source.id='StreamSource', receiver.url='http://localhost/parser', connection.timeout='150000', @map(type='json', @attributes(messageId='trp:messageId'))) 
define stream SourceStream (messageId string, text string, project string, model string);

@sink(type='http-response', source.id='StreamSource', message.id='{{messageId}}', @map(type='json', @payload('{{results}}')) define stream SinkStream (messageId string, results String);

The error I'm getting in the @sink line is that:

Syntax error in SiddhiQL, no viable alternative at input ';\r\n\r\n@sink(type='http-response', source.id='StockStreamSource', message.id='{{messageId}}', @map(type='json', @payload('{{results}}')) define'. no viable alternative at input ';\r\n\r\n@sink(type='http-response', source.id='StockStreamSource', message.id='{{messageId}}', @map(type='json', @payload('{{results}}')) define'

Is there something I'm missing here?


Solution

  • You are missing parentheses at the end of your sink definition. Below is the fixed definition

    @sink(type='http-response', source.id='StreamSource', message.id='{{messageId}}', @map(type='json', @payload('{{results}}'))) 
    define stream SinkStream (messageId string, results String);
    

    You will face issues after this also as you have only mapped messagedID attribute in your input mapping. ie

    @map(type='json', @attributes(messageId='trp:messageId'))
    

    Please map other attributes as well there.