bmpn PUT Endpoint custom handler

170 views
Skip to first unread message

Mark Jayson Gonzaga

unread,
Jun 22, 2021, 6:21:19 AM6/22/21
to kogito-de...@googlegroups.com
Hi Team,

I have a simple scenario below where I'd like to know how I can handle in the code whenever a PUT endpoint has been triggered.

image.png
There is a generated POST endpoint for the Pre-Entry and it is working fine, Now whenever I hit the PUT endpoint it seems the java method attached to that process is not invoking. Therefore I realized that my Java implementation against that is only being invoked wheneter the request is POST.

My question is, how can I handle PUT requests? So that I can do something like check the db, or update the entry.

Thanks,

Cristiano Nicolai

unread,
Jun 22, 2021, 7:07:42 AM6/22/21
to Kogito development mailing list
Mark,

There is an out-of-the-box PUT operation for a given process instance /processId/{instanceId}, which does exactly what you mentioned, updates the variables of the process. By doing that, the state ( variables ) are updated but that doesn't make the process "move".  If you want to make an external request to make a process move from one stage to another, you can probably use a signal instead. That would generate a specific endpoint that you could call which would then trigger the process to move.
You can verify all the generated endpoints by checking the Swagger UI.





--
You received this message because you are subscribed to the Google Groups "Kogito development mailing list" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kogito-developm...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kogito-development/CADNbDsCMM%2BF1d4J7Oyn-fGKchBgZRTtE4MKYDGXp5PBAweZsdQ%40mail.gmail.com.


--
Best regards,

Cristiano Nicolai

Mark Jayson Gonzaga

unread,
Jun 22, 2021, 7:31:45 AM6/22/21
to kogito-de...@googlegroups.com
Hi Cristiano,

image.png
Whenever, I invoke this
image.png
the process method for the ServiceContract is triggered. Which I understand.

However,
Invoking the PUT
image.png
Doesn't trigger the same method. I would like to know if there is a way to handle or listen to the PUT event. as I have to update the data being updated for my reporting that's why.


Cristiano Nicolai

unread,
Jun 22, 2021, 10:15:47 AM6/22/21
to Kogito development mailing list
The POST method initiates a new process instance which will execute all nodes until it reaches a wait state. In your case, it will execute and wait in the PullOut human task node. I think from what you mentioned so far, is that you need to wait for an external system to update the process after it started? If that's the case, that needs to be modelled in the process as such.
A signal could do that, but maybe try to describe what is the use case to have such difference? Like start the process and then update later on?


Mark Jayson Gonzaga

unread,
Jun 22, 2021, 10:29:46 AM6/22/21
to kogito-de...@googlegroups.com
Hi Cristiano,

Thanks for your help. I have discussed it already with my team and came up with a solution.
However, we have 2 more questions.

1. Is there a way to call a GET endpoint paginated?
image.png
2. From the Image below,
image.png
image.png
From the code, how can I get the both the uuid and the task-id? My objective is to save the processed data together with the uuid.

Your help is much appreciated

Thanks,
Mark







Cristiano Nicolai

unread,
Jun 22, 2021, 10:58:35 AM6/22/21
to Kogito development mailing list
On Wed, Jun 23, 2021 at 12:29 AM Mark Jayson Gonzaga <markjayson...@gmail.com> wrote:
Hi Cristiano,

Thanks for your help. I have discussed it already with my team and came up with a solution.
However, we have 2 more questions.

1. Is there a way to call a GET endpoint paginated?

The goal for the REST interface and the runtime, is that it tracks only the process instance that are active, so that is reflected in the operations that are available there. For a more comprehensive API around process data, we usually recommend people to look into the Data Index service. Tha component will collect runtime event messages ( usually via Kafka ) and store that in the database, allowing further querying via a more extensive GraphQL API.


 
image.png
2. From the Image below,
image.png
image.png
From the code, how can I get the both the uuid and the task-id? My objective is to save the processed data together with the uuid.

Perhaps that would be solved by the Data Index as well?

 

Mark Jayson Gonzaga

unread,
Jun 22, 2021, 12:11:36 PM6/22/21
to kogito-de...@googlegroups.com
Hi Cristiano,

I see since it tracks only the process instance that are active, is there a way to automatically set like an expiration date? for each user task or process until it gets completed? or until it proceed to the next user task?

Jakub Grabowski

unread,
Jun 22, 2021, 5:02:49 PM6/22/21
to Kogito development mailing list
Mark,

You can get UUID of a process by:
1. Creating String process variable (eg. myUuid)
2. Creating script task and calling kcontext.setVariable("myUuid", kcontext.getProcessInstance().getStringId())
3. Assigning myUuid as an input to service task, that's able to store it.

However using cloudevents smallrye reactive messaging seems to be better solution. It's a Kogito extension that enables you to retrieve information about process instance events and usertask events when they occur. You can publish them using Kafka, JMS, AMQP or REST endpoint. Cloud events contain all process instance data or user task data including processInstanceId, processId as well as parent process data while using subprocesses.

Another option, as mentioned by Cristiano is data index service, but I prefer to receive event based data rather than query to search them so I've chosen cloudevents path.

Regards,
Jakub.

Mark Jayson Gonzaga

unread,
Jun 22, 2021, 10:38:40 PM6/22/21
to kogito-de...@googlegroups.com
Thanks for your help guys,

I'm currently exploring the Data Index part.
I'm sure I follow everything in the docs. but i got a different result

image.png

Mark Jayson Gonzaga

unread,
Jun 22, 2021, 10:56:08 PM6/22/21
to kogito-de...@googlegroups.com
Hi Jakub,

Could you give me some examples or reference for the cloud events?

Cristiano Nicolai

unread,
Jun 22, 2021, 11:18:40 PM6/22/21
to Kogito development mailing list
Mark,

Basically, you need to setup the kogito-cloudevents-quarkus-addon and kogito-events-reactive-messaging-addon which will give you process events published by the engine in cloud event format. As Jakub mentioned, you can then either consume it yourself or use the Data Index to aggregate that data for you.
There is an extended example here https://github.com/kiegroup/kogito-examples/tree/stable/kogito-travel-agency/extended that showcase how that could work. Regarding the issue you are getting, first step I would say is to check if messages are getting into Kafka? topics. Then check if any error logs are showing in the Data Index.



Mark Jayson Gonzaga

unread,
Jun 23, 2021, 12:01:12 AM6/23/21
to kogito-de...@googlegroups.com
Hi Cristiano,

I was able to get it working, It is just my kafka's topics are not created.
I'm thinking about Jakub's thoughts about consuming events via  JMS, AMQP or REST endpoints. I've been looking in the internet about the usage but can't find

Cristiano Nicolai

unread,
Jun 23, 2021, 12:10:22 AM6/23/21
to Kogito development mailing list
Mark, the kogito-events-reactive-messaging-addon relies on SmallRye Reactive messaging, so you should be able to plug any of the connector available in here https://smallrye.io/smallrye-reactive-messaging/smallrye-reactive-messaging/3.5/connectors/connectors.html

Jakub Grabowski

unread,
Jun 23, 2021, 3:19:24 AM6/23/21
to Kogito development mailing list
pom.xml: 

<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging</artifactId>
</dependency>
<dependency>
<groupId>io.smallrye.reactive</groupId>
<artifactId>smallrye-reactive-messaging-http</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-events-reactive-messaging-addon</artifactId>
</dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
<artifactId>kogito-cloudevents-quarkus-addon</artifactId>
</dependency>

application.properties:

mp.messaging.outgoing.kogito-usertaskinstances-events.connector=smallrye-http
mp.messaging.outgoing.kogito-usertaskinstances-events.url=http://localhost:8080/cloudevents/usertask

mp.messaging.outgoing.kogito-processinstances-events.connector=smallrye-http
mp.messaging.outgoing.kogito-processinstances-events.url=http://localhost:8080/cloudevents/processinstance

Hope it helps,
Jakub.

Mark Jayson Gonzaga

unread,
Jul 12, 2021, 1:32:06 PM7/12/21
to kogito-de...@googlegroups.com
Hi jakub,

Wondering how you were able to use ActiveMQ instead of Kafka, I tried it but it didn't work. My 2 services don't communicate at all

Here the dependencies for both projects
<dependencies>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-grpc</artifactId>
  </dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
    <artifactId>kogito-quarkus</artifactId>
  </dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
    <artifactId>kogito-addons-quarkus-cloudevents</artifactId>
</dependency>
  <dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging</artifactId>
</dependency>
<dependency>
    <groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-reactive-messaging-amqp</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-smallrye-openapi</artifactId>
  </dependency>
<dependency>
<groupId>org.kie.kogito</groupId>
    <artifactId>kogito-addons-quarkus-events-smallrye</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-hibernate-reactive</artifactId>
</dependency>
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-reactive-pg-client</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<version>1.18.20</version>
<scope>provided</scope>
</dependency>
</dependencies>

Service 1
amqp-username=quarkus
amqp-password=quarkus
#kafka.bootstrap.servers=${KAFKA_BOOTSTRAP_SERVERS:localhost:9092}

mp.messaging.incoming.kogito_incoming_stream.connector=smallrye-amqp
mp.messaging.incoming.kogito_incoming_stream.topic=servicecontractresponses
#mp.messaging.incoming.kogito_incoming_stream.value.deserializer=org.apache.kafka.common.serialization.StringDeserializer

mp.messaging.outgoing.kogito_outgoing_stream.connector=smallrye-amqp
mp.messaging.outgoing.kogito_outgoing_stream.topic=servicecontractapplications
#mp.messaging.outgoing.kogito_outgoing_stream.value.serializer=org.apache.kafka.common.serialization.StringSerializer

## metadata
mp.messaging.outgoing.kogito-processinstances-events.connector=smallrye-amqp
mp.messaging.outgoing.kogito-processinstances-events.topic=kogito-processinstances-events
#mp.messaging.outgoing.kogito-processinstances-events.value.serializer=org.apache.kafka.common.serialization.StringSerializer

mp.messaging.outgoing.kogito-usertaskinstances-events.connector=smallrye-amqp
mp.messaging.outgoing.kogito-usertaskinstances-events.topic=kogito-usertaskinstances-events
#mp.messaging.outgoing.kogito-usertaskinstances-events.value.serializer=org.apache.kafka.common.serialization.StringSerializer

mp.messaging.outgoing.kogito-variables-events.connector=smallrye-amqp
mp.messaging.outgoing.kogito-variables-events.topic=kogito-variables-events
#mp.messaging.outgoing.kogito-variables-events.value.serializer=org.apache.kafka.common.serialization.StringSerializer

Service 2
amqp-username=quarkus
amqp-password=quarkus
#kafka.bootstrap.servers=${KAFKA_BOOTSTRAP_SERVERS:localhost:9092}

mp.messaging.incoming.kogito_incoming_stream.connector=smallrye-amqp
mp.messaging.incoming.kogito_incoming_stream.topic=servicecontractapplications
#mp.messaging.incoming.kogito_incoming_stream.value.deserializer=org.apache.kafka.common.serialization.StringDeserializer
mp.messaging.incoming.kogito_incoming_stream.durable=true

mp.messaging.outgoing.kogito_outgoing_stream.connector=smallrye-amqp
mp.messaging.outgoing.kogito_outgoing_stream.topic=servicecontractresponses
#mp.messaging.outgoing.kogito_outgoing_stream.value.serializer=org.apache.kafka.common.serialization.StringSerializer

mp.messaging.outgoing.kogito-processinstances-events.connector=smallrye-amqp
mp.messaging.outgoing.kogito-processinstances-events.topic=kogito-processinstances-events
#mp.messaging.outgoing.kogito-processinstances-events.value.serializer=org.apache.kafka.common.serialization.StringSerializer

mp.messaging.outgoing.kogito-usertaskinstances-events.connector=smallrye-amqp
mp.messaging.outgoing.kogito-usertaskinstances-events.topic=kogito-usertaskinstances-events
#mp.messaging.outgoing.kogito-usertaskinstances-events.value.serializer=org.apache.kafka.common.serialization.StringSerializer

mp.messaging.outgoing.kogito-variables-events.connector=smallrye-amqp
mp.messaging.outgoing.kogito-variables-events.topic=kogito-variables-events
#mp.messaging.outgoing.kogito-variables-events.value.serializer=org.apache.kafka.common.serialization.StringSerializer
But when I tried to put it back to kafka it was working.

Jakub Grabowski

unread,
Jul 12, 2021, 1:36:58 PM7/12/21
to kogito-de...@googlegroups.com
I believe you should use .address and not .topic for amqp.


Cheers,
Jakub.

Mark Jayson Gonzaga

unread,
Jul 12, 2021, 1:52:12 PM7/12/21
to kogito-de...@googlegroups.com
Thanks Jakub you are the best.

One last question if it is not too much to ask. 
I've been checking the past threads and you sent this

mp.messaging.outgoing.kogito-usertaskinstances-events.connector=smallrye-http
mp.messaging.outgoing.kogito-usertaskinstances-events.url=http://localhost:8080/cloudevents/usertask

mp.messaging.outgoing.kogito-processinstances-events.connector=smallrye-http
mp.messaging.outgoing.kogito-processinstances-events.url=http://localhost:8080/cloudevents/processinstance


Could you please point me in the right resources about this : http://localhost:8080/cloudevents/processinstance
So far what I've been using is the data-index (GitHub - kiegroup/kogito-images: Images for Kogito) Which doesn't have support for the amqp.

Thanks.

Jakub Grabowski

unread,
Jul 12, 2021, 2:06:11 PM7/12/21
to kogito-de...@googlegroups.com
Those http endpoints that I was mentioning are my custom REST services on Wildfly, listening on incoming cloudevent messages from the process.

Mark Jayson Gonzaga

unread,
Jul 12, 2021, 2:21:50 PM7/12/21
to kogito-de...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages