I have an avahi (zeroconf, dnssd, bonjour) service. I want the service to be able to notify the clients when it has new data so the clients can then connect and query for the updated information.
What type of message should the service publish, and how is this done with the avahi API (service is written in C++)?
I don't know what C++ API you are refering to, but this is how you do it in the C-layer. You can use the following functions in avahi to update the TXT record of the service.
avahi_entry_group_update_service_txt (AvahiEntryGroup *g, ...)
avahi_entry_group_update_service_txt_strlst (AvahiEntryGroup *g, ...)
Listening clients will receive a service updated event.
Related
I am using graph-gophers library to build graphql application on the server side. I have a lambda works as resolvers and websocket apigateway which works as transport layer. The lambda will take the request from apigateway then call graph-gophers library schema methods to trigger resolver. It works well for query and mutation. But I am not sure how to make it work for subscription.
The library graph-gophers requires the subscription resolver to return a go channels which it listens to. but in case of lambda which is a short lived application, it can't keep alive for a long time. That means I can't use channel for publishing data.
What I am doing is to save the socket connection id on a database, when there is a need to publish data, I will grab the connection id from db to find all the subscribers. But I don't know how to trigger the publish in this case. Anyone has any idea about how to do that?
So I need to build a WebSocket API for my org. The requirements from the business are pretty typical websocket pattern stuff except for one detail:
This websocket api will be used by different teams in our org, and each team needs its own separate activeconnections dynamodb table.
Now in a typical websocket api, there would be a single connections table that the connect and disconnect lambda functions write/delete to. Also, the hooks in the websocket api ensure that the connectionId needed to identify a connection/session are always in the event.requestContext. Easy peasy for a single connections table.
However, In my approach of having a separate active connections db/table for each team, it gets more complicated. Yes, it's true that for the connect lambda, It is very easy to code so that it expects a "TeamDatabaseID" from somewhere in the initial connection request - Headers, queryStringParameters, etc.
The problem is in the subsequent disconnect that could be triggered from either client or server. The disconnect hook will run the disconnect function, and pass in the default requestContext with the connectionId, but with no TeamDatabaseID - which the disconnect lambda needs to have access to in order to know which database to delete from.
Is there a way to do this? Is there some notion of a context object that I can set values in from the initial connection, so that when the disconnect happens, the teamDatabaseID is propagated in some way to the subsequent disconnect lambda? I tried writing to the requestContext - and that seems to only be alive for the execution of the given lambda.
Instead of having a single Amazon API Gateway Web Socket API for multiple teams, could you instead have one Web Socket API per team?
I've been trying to use the javacscript version of the Eclipse Paho MQTT client to access the Google IOTCore MQTT Bridge, as suggested here:
https://cloud.google.com/iot/docs/how-tos/mqtt-bridge
However, whatever I do, any attempt to connect with known good credentials (working with other clients) results in this connection error:
errorCode: 7, errorMessage: "AMQJS0007E Socket error:undefined."
Not much to go on there, so I'm wondering if anyone has ever been successful connecting to the MQTT Bridge via Javascript with Eclipse Paho, the client implementation suggested by Google in their documentation.
I've gone through their troubleshooting steps, and things seem to be on the up and up, so no help there either.
https://cloud.google.com/iot/docs/troubleshooting
I have noticed that in their docs they have sample code for Java/Python, etc, but not Javascript, so I'm wondering if it's simply not supported and their documentation just fails to mention as such.
I've simplified my code to just use the 'Hello World' example in the Paho documentation, and as far as I can tell I've done things correctly (including using my device path as the ClientID, the JWT token as the password, specifying an 'unused' userName field and explicitly requiring MQTT v3.1.1).
In the meantime I'm falling back to polling via their HTTP bridge, but that has obvious latency and network traffic shortcomings.
// Create a client instance
client = new Paho.MQTT.Client("mqtt.googleapis.com", Number(8883), "projects/[my-project-id]/locations/us-central1/registries/[my registry name]/devices/[my device id]");
// set callback handlers
client.onConnectionLost = onConnectionLost;
client.onMessageArrived = onMessageArrived;
// connect the client
client.connect({
mqttVersion: 4, // maps to MQTT V3.1.1, required by IOTCore
onSuccess:onConnect,
onFailure: onFailure,
userName: 'unused', // suggested by Google for this field
password: '[My Confirmed Working JWT Token]' // working JWT token
function onFailure(resp) {
console.log(resp);
}
// called when the client connects
function onConnect() {
// Once a connection has been made, make a subscription and send a message.
console.log("onConnect");
client.subscribe("World");
message = new Paho.MQTT.Message("Hello");
message.destinationName = "World";
client.send(message);
}
// called when the client loses its connection
function onConnectionLost(responseObject) {
if (responseObject.errorCode !== 0) {
console.log("onConnectionLost:"+responseObject.errorMessage);
}
}
// called when a message arrives
function onMessageArrived(message) {
console.log("onMessageArrived:"+message.payloadString);
}
I'm a Googler (but I don't work in Cloud IoT).
Your code looks good to me and it should work. I will try it for myself this evening or tomorrow and report back to you.
I've spent the past day working on a Golang version of the samples published on Google's documentation. Like you, I was disappointed to not see all Google's regular languages covered by samples.
Are you running the code from a browser or is it running on Node.JS?
Do you have a package.json (if Node) that you would share too please?
Update
Here's a Node.JS (JavaScript but non-browser) that connects to Cloud IoT, subscribes to /devices/${DEVICE}/config and publishes to /devices/${DEVICE}/events.
https://gist.github.com/DazWilkin/65ad8890d5f58eae9612632d594af2de
Place all the files in the same directory
Replace values in index.js of the location of Google's CA and your key
Replaces [[YOUR-X]] values in config.json
Use "npm install" to pull the packages
Use node index.js
You should be able to pull messages from the Pub/Sub subscription and you should be able to send config messages to the device.
Short answer is no. Google Cloud IoT Core doesn't support WebSockets.
All the JavaScript MQTT libraries use WebSocket because JavaScript is restricted to perform HTTP requests and WebSocket connections only.
I am developing a CICS web service requestor application to consume a distributed web service. I used the web services assistant DFHWS2LS to transform the wsdl to copybooks successfully.
I have no problem issuing the PUT CONTAINER and INVOKE SERVICE api commands, but when I issue GET CONTAINER to get response, the DFHWS-DATA container still contains the request (data sent in put container) data only.
DFHRESPONSE container has the response from distributed system but CICS is not converting it into my application copybook structure.
Be certain to check the RESP and RESP2 values returned by the INVOKE SERVICE API.
Take a look in the TD queue mapped to CSSL (the default is the MSGUSR DD) for your CICS region. This is where CICS logs messages when it runs into an error while processing your SOAP request. Look for messages prefixed DFHPI.
I am developing a CICS web service requestor application to consume a distributed web service.
I used the web services assistant DFHWS2LS to transform the wsdl to copybooks successfully.
I have no problem issuing the PUT CONTAINER and INVOKE SERVICE api commands, but when I issue GET CONTAINER I am not receiving any containers or data. No response codes or error messages, but no data. Any ideas on how to debug this would be greatly appreciated.
Thanks,
I have never seen RESP be DFHRESP(NORMAL) and RESP2 be zero and have nothing returned by the server.
Verify the WSDL specifies that something is, in fact, returned by the web service.
Check the RESP and RESP2 values returned by the INVOKE SERVICE API. You don't mention these explicitly, and I presume the former is DFHRESP(NORMAL) and the latter is 0, but you might have coded NOHANDLE so I thought I'd ask.
Take a look in the TD queue mapped to CSSL (the default is the MSGUSR DD) for your CICS region. This is where CICS logs messages when it runs into an error while processing your SOAP request. Look for messages prefixed DFHPI.
Try pinging the endpoint from a TSO session running on the same LPAR as your CICS region, it's possible you're being stopped by a firewall.
In your comment you indicate the requestor is "seeing whitespace on the <SOAP-ENV:Envelope tag>". This isn't something under your direct control. The CICS "plumbing" code takes care of formatting the SOAP message. You may want to ask your CICS Systems Programmer to look for APARs related to the problem and install any associated PTFs.
You could verify the requestor's claim by using the transport handler in Appendix A.3 of this redbook. You'll have to modify your pipeline configuration file to execute the handler.