How to produce Kafka message with kcat? - json

I'm trying to produce Kafka message with kcat tool. I have a message that follows topic schema:
{
"meta": {
"correlationId": "244c7ed3-0472-496e-bed9-7071f8ddb921",
"payload": {
"id": "3ae843e9-0c96-4ee8-b1f0-fbdfef30e9dd",
"timestamp": 1658846522
}
}
}
store it to the file k-msg-test.json and run kcat:
kcat \
-b localhost:9092 \
-r localhost:8081 \
-t test-topic \
-T \
-P \
/tmp/k-msg-test.json
and I get an error:
% Failed to open : No such file or directory
/tmp/k-msg-test.json: line 2: meta:: command not found
/tmp/k-msg-test.json: line 3: correlationId:: command not found
/tmp/k-msg-test.json: line 4: payload:: command not found
/tmp/k-msg-test.json: line 5: id:: command not found
/tmp/k-msg-test.json: line 6: timestamp:: command not found
/tmp/k-msg-test.json: line 8: syntax error near unexpected token `}'
/tmp/k-msg-test.json: line 8: ` }'
So the question is – how can I produce a message?

Your file is apparently being interpreted as literal text to your shell rather than read by kcat.
You need to use shell redirection as kcat accepts stdin, rather than file arguments.
You'll also need to remove the new lines and produce as a single line. You can do that with jq
kcat \
-b localhost:9092 \
-r localhost:8081 \
-t test-topic \
-T \
-P < $(jq -rc '.' /tmp/k-msg-test.json)

Related

Can't create task scheduler with groovy script in nexus3.x

I want to create a script with helping of this document but I don't know how to pass a groovy file instead of json and when I execute
curl -u admin:admin123 -X POST --header 'Content-Type: application/json' \ ─╯
http://<url>/service/rest/v1/script \
-d create_task.groovy
I got this error:
{ "id" : "*", "message" : "Could not process the input:
Unrecognized token 'create_task': was expecting (JSON String, Number,
Array, Object or token 'null', 'true' or 'false')" }%
Any help would be appreciated!
enter code hereI found the solution!
you have to first convert that groovy script to a JSON file and pass that JSON file to your curl or API(for creating script) that you are working with and we can do it with this python file:
import json
with open("[THE GROOVY FILE]", "r") as inputfile:
filedata = inputfile.read()
jsondata = {}
jsondata['name'] = 'testscript2'
jsondata['type'] = 'groovy'
jsondata['content'] = filedata
with open("[OUTPUT FILE]", "w") as outputfile:
outputfile.write(json.dumps(jsondata))
the output file is something like this:
{
"name": "name",
"type": "groovy",
"content": "..."
}
then use this output file which is a JSON file and pass this to that command and there you go!
the command for creat script with REST API is:
curl -v -X POST -u admin:admin --header "Content-Type: application/json" "http://<url>/service/rest/v1/script" -d #{output}.json
the above command will create a script and you can execute it with:
curl -v -X POST -u admin:admin --header "Content-Type: application/json" "http://<url>/service/rest/v1/script/{name}/run

Can't curl post with JSON to a remote machine: "was expecting double-quote to start field name"

I'm trying to post a trace to a remote machine by giving the trace path and name as parameters in the curl command like this:
sshpass -p password ssh username#ip_adress "curl -X POST -d '{"parameters":{"name":"trace","uri":"/usagers4/username/Documents/Bench_1/kernel"}}' http://0.0.0.0:8080/tsp/api/traces -H Accept:application/json -H Content-Type:application/json"
But I'm getting the following error:
javax.servlet.ServletException: org.glassfish.jersey.server.ContainerException: com.fasterxml.jackson.core.JsonParseException: Unexpected character ('p' (code 112)): was expecting double-quote to start field name| at [Source: (org.glassfish.jersey.message.internal.ReaderInterceptorExecutor$UnCloseableInputStream); line: 1, column: 3]
Does anyone have an idea about what I'm doing wrong ?
Thanks
I Solved!
i'm need to get out for python use os.system(Curl ... )
it command return code 112 double quote to start field name
i'm use os.system("curl -d '{\"agr\" : value}' -H 'value' -H 'value' ... etc.")
you should use the following code
"curl -X POST -d '{\"parameters\":{\"name\":\"trace\",\"uri\":\"/usagers4/username/Documents/Bench_1/kernel\"}}' http://0.0.0.0:8080/tsp/api/traces -H 'Accept:application/json' -H 'Content-Type:application/json'"

Sending jq via SSH

When I running jq command locally it works:
jq --arg ip "$IP" '.nodes|.app|.ip = $ip' nodes.json
Output:
{
"nodes": 1,
"is_manager": true,
"ip": "127.0.0.1",
"cpus": 16,
"memory": 64
}
But I can't figure out how do I send it remotely via ssh, for example this command returns an error:
ssh -o StrictHostKeyChecking=no -i key.pem user#"172.13.1.23" "jq --arg ip "127.0.0.1" '.nodes|.app|.ip = $ip' nodes.json"
Output:
jq: error: syntax error, unexpected $end (Unix shell quoting issues?) at , line 1:
.nodes|.app|.ip =
jq: 1 compile error
$ip is in double quotes, and so is expanded locally. You need to escape the dollar sign.
ssh -o StrictHostKeyChecking=no -i key.pem user#"172.13.1.23" \
"jq --arg ip "127.0.0.1" '.nodes|.app|.ip = \$ip' nodes.json"

Crooscompile qt5.4 for imx6

I am trying to crosscompile qt-everywhere-opensource-5.4.0 to iMx6 board.
The following is my configuration file (config.imx6):
./configure --prefix=/tools/rootfs/usr/local/qt-5.4.0 -examplesdir /tools/rootfs/usr/local/qt-5.4.0/examples -verbose -opensource -confirm-license -make libs -make examples -device imx6 \
-device-option CROSS_COMPILE=\
/home/acsia/Desktop/imx6-Qt5/arm-tool-chain/freescale/usr/local/gcc-4.6.2-glibc-2.13-linaro-multilib-2011.12/fsl-linaro-toolchain/bin/arm-fsl-linux-gnueabi- \
-no-pch -no-opengl -no-icu -no-xcb -no-c++11 \
-opengl es2 \
-eglfs \
-compile-examples \
-glib -gstreamer -pkg-config -no-directfb\
When I run ./config.imx I am getting following error:
-gstreamer: invalid command-line switch
But same configuration file runs fine qt-everywhere-opensource-5.1.1
The platform I am using is ubuntu 14.04.
How do I resolve this?

query argument of mongoexport

What is the right format of query argument of mongoexport utility?
While running the following command in the command line:
mongoexport -h localhost:27000 -d dbName -c collName -q "{'time': { $gt: new Date('2014-01-28T12:00:00Z')}}" -o output.js
I'm getting the following error:
connected to: localhost:27000 assertion: 16619 code FailedToParse:
FailedToParse: Expecting '}' or ',': offset:37
Reading Mongo Export query arg and JSONDocument docs haven't helped me to understand the expected format of query argument.
Running the same query in mongo shell succeeds.
If:
>new Date ("2014-01-28T12:00:00Z").getTime()
1390910400000
You will have to construct your query as follows:
-q "{sendToServerTime: {\$gt: {\$date : 1390910400000}}}"
The problem is your new Date() command. This no valid json. Try this:
mongoexport -h localhost:27000 -d DeploymentJan01 -c sensorsData -q '{sendToServerTime: { $gt: "2014-01-28T12:00:00Z"}}' -o output.js