on 01-13-2020 5:23 AM
Hi,
I have created an Enterprise Messaging Instance in Cloud Platform, How to use that in an Application built using Cloud Application Programming Model(CAP). What needs to be done next.?
Any lead is welcome.
Thanks.
Hi,
you Need to do the following steps (assuming you have productive account in Cloud Foundry):
* Bind your CAP application to the msg instance (-> manifest.yml)
* In your package.json add entry to cds-requires section:
"cds":
{
"requires":
{
"anyMessagingName":
{
"kind":
"enterprise-messaging","credentials": {
"namespace":
"my/own/ns"
The
chosen name (anyMessagingName) will be referenced in code
The
“namespace” (my/own/ns) will be used by CAP to generate a queue
Make sure that the Namespace is compliant to your Topic rules, as defined when creating a Messaging instance
* In your custom Code handler, you connect to e.g. "anyMessagingName"
* example for emit:
const msg =
cds.connect.to('anyMessagingName‘)
const payload =
{
"theName":
"myName",
"theChangeId":
"123"
}
msg.emit('myEventName', payload)
* to consume an Event/resp message, you configure your consuming CAP app in the same way
* In the custom Code, you connect to your declared anyMessagingName in the same way
to react upon Events, you write the same custom handler Code as used to
With one difference in case of Enterprise messaging: you specify a Topic. In productive account, this is concatenated with the Namespace:
const msg = cds.connect.to('anyMessagingName‘)
msg.on('my/own/ns/BO/BusinessPartner/Changed', async (msg) => {
Once you have understood and configured, it is easy to use 😉
Kind Regards,
Carlos
BTW, here's the link to the docu: https://cap.cloud.sap/docs/guides/consuming-services#emitting-events
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
One more addendum:
Since CAP version 3.30, the API has slightly changed:
We don't need to connect to a new messaging-configuration
Instead, we configure our own service as follows
package.json:
"cds": {
"requires": {
"messaging": {
"kind": "enterprise-messaging"
}
}
},
service.js
no connect necessary.
Just use the srv instance
module.exports = cds.service.impl ((srv) => {
srv.on('company/customer/care/demo/customer/created', async (msg) => {
const messagePayload = JSON.stringify(msg.data)
console.log('===> Received message : ' + messagePayload)
})
and for sending:
const message = {
'myProp': 'Sending message.'
}
const topic = 'company/customer/care/demo/customer/created'
srv.emit (topic, message)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
In the meantime, I've started publishing a little series of tutorials about CAP and messaging:
https://blogs.sap.com/2020/03/03/sap-cloud-application-programming-model-and-enterprise-messaging-1-...
https://blogs.sap.com/2020/03/03/sap-cloud-application-programming-model-and-enterprise-messaging-2-...
https://blogs.sap.com/2020/03/03/sap-cloud-application-programming-model-and-enterprise-messaging-3-...
Note that currently, the CAP-integration of Enterprise Messaging is still in beta-mode, so there might be incompatible changes.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello al5370 , I don't think that's possible to solve right now, because the FWK reads from binding and thus requires binding and fails during deploy if not bound
What you can do is to manually use the amqp lib
Kind Regards, Carlos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Is there support for consuming messages from kafka using CAP?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hello, Is there any configuration using which we can create webhook automatically through application service itself ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi, as I mentioned, the configuration is the same:
"cds":{
"requires":{"anyMessagingName":{ "kind":"enterprise-messaging","credentials": {"namespace":"my/own/ns"
and in the JavaScript, you do the Connection:
const msg = cds.connect.to('anyMessagingName‘)
and you add an Event listener
msg.on('my/own/ns/BO/BusinessPartner/Changed', async (msg)=>{
the msg contains the message, Access it with
msg.data
I want to publish a blog, but it will take time, I'm sorry
Cheers,
Carlos
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Carlos,
What if you can't bind to the messaging service because you are in a different space. And you need to use de clientid and secret. How do you set this up in the package.json
thanks in advanced
Erik
User | Count |
---|---|
80 | |
9 | |
9 | |
7 | |
7 | |
7 | |
6 | |
5 | |
5 | |
5 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.