How to connect apache kafka to eclipse ditto? - apache-kafka

I'm trying to connect apache kafka 2.x to eclipse ditto in locally with default configurations.
I'm following this https://www.eclipse.org/ditto/connectivity-protocol-bindings-kafka2.html, so I tried to create a new connection with a POST request, as follows:
curl -X POST -i -u devops:foobar -H 'Content-Type: application/json' -d '{
"targetActorSelection":"/system/sharding/connection",
"headers":{
"aggregate":false
},
"piggybackCommand":{
"type":"connectivity.commands:createConnection",
"connection":{
"id":"kafka123",
"connectionType":"kafka",
"connectionStatus":"open",
"failoverEnabled":true,
"uri":"tcp://localhost:9092",
"specificConfig":{
"bootstrapServers":"localhost:9092"
},
"sources":[
{
"addresses":["topic01"],
"consumerCount":1,
"qos":0,
"authorizationContext":["nginx:ditto"],
"enforcement":{
"input":"{{ header:device_id }}",
"filters":["{{ entity:id }}"]
},
"headerMapping":{
"topic01":"{{ header:topic01 }}",
"the-key":"{{ header:kafka.key }}"
},
"payloadMapping":["Ditto"],
"replyTarget":{
"enabled":true,
"address":"topic01",
"headerMapping":{
},
"expectedResponseTypes":[
"response",
"error",
"nack"
]
},
"acknowledgementRequests":{
"includes":[]
},
"declaredAcks":[]
}
]
}
}
}' 'http://localhost:8080/devops/piggyback/connectivity?timeout=10'
This is the result:
HTTP/1.1 408 Request Timeout
Server: nginx/1.21.6
Date: Wed, 18 May 2022 14:11:33 GMT
Content-Type: application/json
Content-Length: 4
Connection: keep-alive
correlation-id: 16231ebe-3cd1-4ec1-9f42-ad58b9b82d14
timeout: 10
response-required: false
Access-Control-Allow-Methods: GET, POST, PUT, PATCH, DELETE, OPTIONS
Access-Control-Allow-Credentials: true
Access-Control-Expose-Headers: *
null%
I can't understand what I'm doing wrong. how can i solve?

I solved: Checking in the ditto-connectivity logs (on docker), I found an error regarding a java library. To solve the problem I followed the installation of ditto again (https://github.com/eclipse/ditto#getting-started).
After that, the command written in my question worked and I got a 200 response.

Seems nginx could not send your request over to ditto services. Maybe some of ditto services are not running or you are trying to use a wrong port 8080 (if you followed the instructions for ditto setup, it should be 30080).
Please check if all ditto pods are running (use 'kubectl get pods') and which port your ditto listen on (use 'kubectl get svc')

Related

Snowflake connector "Cannot connect to Snowflake"

I was working with Kafka and try to connect snowflake with it but it's not connecting.
It gives some kind of regional error that the server and cluster should be on the same region, and I tried it on local Kafka and did not accept the "snowflake.url.name".
here is the config file in distributed mode.
curl -i -X POST -H "Accept:application/json" -H "Content-Type:application/json" localhost:8083/connectors/ -d '
{
"name":"XYZCompanySensorData",
"config":{
"connector.class":"com.snowflake.kafka.connector.SnowflakeSinkConnector",
"tasks.max":"2",
"topics":"MysqlJConfluent.source.user_details",
"buffer.count.records":"10000",
"buffer.flush.time":"60",
"buffer.size.bytes":"5000000",
"snowflake.url.name":"fk79721.europe-west2.gcp.snowflakecomputing.com",
"snowflake.user.name":"********",
"snowflake.private.key":"********************************************",
"snowflake.database.name":"DEMO_DB",
"snowflake.schema.name":"PUBLIC",
"key.converter":"org.apache.kafka.connect.storage.StringConverter",
"value.converter":"com.snowflake.kafka.connector.records.SnowflakeAvroConverter"
}
}'
Log file :
HTTP/1.1 100 Continue
HTTP/1.1 400 Bad Request
Date: Wed, 28 Apr 2021 11:50:41 GMT
Content-Type: application/json
Content-Length: 368
Server: Jetty(9.4.33.v20201020)
{"error_code":400,"message":"Connector configuration is invalid and contains the following 3 error(s):\nsnowflake.url.name: Cannot connect to Snowflake\nsnowflake.user.name: Cannot connect to Snowflake\nsnowflake.private.key: Cannot connect to Snowflake\nYou can also find the above list of errors at the endpoint `/connector-plugins/{connectorType}/config/validate`"}
Please let me know how can I connect.
This line:
"snowflake.url.name":"fk79721.europe-west2.gcp.snowflakecomputing.com
shows that you're not closing the quotes, and it should be like this:
"snowflake.url.name":"fk79721.europe-west2.gcp.snowflakecomputing.com:443"

How to add a package to the XQuery repository?

I am using cURL to execute commands using the REST interface of BaseX like this:
curl http://localhost:8984/rest/?command=repo+list
There are also commands to manage the XQuery module repository. I am especially interested in REPO INSTALL to install a package. Is it somehow possible to execute this command using cURL and the REST interface but without having the package already on the target server? I want to provide the file in the body of the cURL request, similar to adding a resource to a database (source) which goes like this:
curl -i -X PUT -T "etc/xml/factbook.xml" "http://localhost:8984/rest/factbook"
Trying
curl -i -X PUT -T "/tmp/foo.xar" http://localhost:8984/rest/?command=repo+install
Gives me
HTTP/1.1 404 Not Found
Content-Type: text/plain;charset=UTF-8
Content-Length: 18
Connection: close
Server: Jetty(9.4.18.v20190429)
No path specified.
Adding -H "Content-Type: application/x-xar" does not help either.
And replacing PUT with POST gives me
HTTP/1.1 100 Continue
HTTP/1.1 400 Bad Request
Date: Tue, 03 Mar 2020 09:53:21 GMT
Content-Type: text/plain;charset=utf-8
Content-Length: 46
Server: Jetty(9.4.18.v20190429)
"" (Line 1): Content is not allowed in prolog.
The following works in case of standard modules (replace user/pass/server if needed):
$ curl http://admin:admin#localhost:8984/rest/?command=repo+install+http://www.xqueryfunctions.com/xq/functx-1.0.1-doc.xq

Unable to create marklogic rest api instance

I am trying to create rest-api instance with the following configuration:
rest-api.json
{
"rest-api": {
"name": "restdb-api",
"database": "restdb",
"port": "8003",
"xdbc-enabled": true,
"forests-per-host": 1,
"error-format": "json"
}
}
curl --anyauth --user admin:admin -i -X POST -d #"./REST/rest-api.json" -H "Content-type: application/json" http://localhost:8002/LATEST/rest-apis
The endpoint returns 201 created, but I am unable to access the created endpoint at http://localhost:8003. I have tried using other ports, but the same thing is happening. The port 8003 is not listening. Please help me solve this problem.
HTTP/1.1 401 Unauthorized
Server: MarkLogic
WWW-Authenticate: Digest realm="public", qop="auth", nonce="36473d01f5e45a:ND9/6NHD0sw9o2y/xad/uQ==", opaque="e9594a1b7e019a97"
Content-Type: text/html; charset=utf-8
Content-Length: 209
Connection: Keep-Alive
Keep-Alive: timeout=5
HTTP/1.1 201 Created
Server: MarkLogic
Content-Length: 0
Connection: Keep-Alive
Keep-Alive: timeout=5
Since you said you are running on a local docker container, you might need to publish the port.
See Docker Expose
Please note from the link that - "The EXPOSE instruction does not actually publish the port. It functions as a type of documentation between the person who builds the image and the person who runs the container, about which ports are intended to be published. To actually publish the port when running the container, use the -p flag on docker run to publish and map one or more ports, or the -P flag to publish all exposed ports and map them to high-order ports."
Hope that helps!

Fiware-Service HTTP header needed for Orion CB

Trying to connect to my Orion CB which has entities created via IoTAgentCPP/IDAS. Both are of latest Docker version (okt 30 2015). All works fine using the FIGWAY Python scripts: Creating IDAS Service, Register Device, Send Observation, see Entity created and changed attributes via OCB.
But using any WireCloud Mashup widget like the NGSI Browser Widget that sends NSGI requests to the OCB the widget remains blanc, since the OCB sends back:
{
"errorCode" : {
"code" : "404",
"reasonPhrase" : "No context element found"
}
}
This reply is also received when querying via curl:
curl my_remote_ocb_host:1026/v1/contextEntities -S --header 'Accept: application/json'
If I add the header --header 'Fiware-Service: fiwareiot' (which was specified when creating the IoT service w IDAS) to the curl-command line, then I get expected responses from the OCB.
However, the Widgets and Operators in WC have no means to add the Fiware-Service HTTP-Header. This is what I receive from WC via the Lab proxy, using protocol capture, at the OCB host:
POST /v1/queryContext?limit=20&details=on&offset=0 HTTP/1.1
Host: <myhost>:1026
origin: https://mashup.lab.fiware.org
Cookie: ..
Content-Length: 45
via: 1.1 mashup.lab.fiware.org (Wirecloud-python-Proxy/1.1)
accept-language: en-US,en;q=0.8,de;q=0.6,fr;q=0.4,nl;q=0.2,it;q=0.2
accept-encoding: gzip, deflate
x-forwarded-host: <myhost>:1026
x-forwarded-for: ..
accept: application/json
user-agent: ..
connection: keep-alive
x-requested-with: XMLHttpRequest
referer: https://mashup.lab.fiware.org/justb4/GeonovumTemperature1
X-Auth-Token: ..
content-type: application/json
{"entities":[{"id":".*","isPattern":"true"}]}
Response: HTTP/1.1 200 OK
Content-Length: 94
Content-Type: application/json
Date: Sat, 31 Oct 2015 13:23:44 GMT
{
"errorCode" : {
"code" : "404",
"reasonPhrase" : "No context element found"
}
}
Possibly the settings for WC Widgets/Operators need to be extended to allow for Fiware-Service HTTP headers, or is there another way for doing this using the current possibilities?
WireCloud supports adding the FIWARE-Service header when programming widgets and operators (see the documentation for more info). So this can be fixed by updating the basic set of widgets and operators provided in FIWARE Lab to support the FIWARE-Service header.
I have created an ticket in the issue tracker of the NGSI Browser widget for you. Please, create such a ticket for the other widgets/operators.
NOTE: You can go to the issue tracker of a component if opening their details and clicking on the issue tracker button:

using wget against protected site with NTLM

Trying to mirror a local intranet site and have found previous questions using 'wget'. It works great with sites that are anonymous, but I have not been able to use it against a site that is expecting username\password (IIS with Integrated Windows Authentication).
Here is what I pass in:
wget -c --http-user='domain\user' --http-password=pwd http://local/site -dv
Here is the debug output (note I replaced some with dummy values obviously):
Setting --verbose (verbose) to 1
DEBUG output created by Wget 1.11.4 on Windows-MSVC.
--2009-07-14 09:39:04-- http://local/site
Host `local' has not issued a general basic challenge.
Resolving local... seconds 0.00, x.x.x.x
Caching local => x.x.x.x
Connecting to local|x.x.x.x|:80... seconds 0.00, connected.
Created socket 1896.
Releasing 0x003e32b0 (new refcount 1).
---request begin---
GET /site/ HTTP/1.0
User-Agent: Wget/1.11.4
Accept: */*
Host: local
Connection: Keep-Alive
---request end---
HTTP request sent, awaiting response...
---response begin---
HTTP/1.1 401 Access Denied
Server: Microsoft-IIS/5.1
Date: Tue, 14 Jul 2009 13:39:04 GMT
WWW-Authenticate: Negotiate
WWW-Authenticate: NTLM
Content-Length: 4431
Content-Type: text/html
---response end---
401 Access Denied
Closed fd 1896
Unknown authentication scheme.
Authorization failed.
NTLM authentication is broken in wget 1.11, use 1.10 instead.
Curl is actually probably a better tool for fetching content from NTLM-authenticated web servers. You can get an equivalent function to your proposed wget command line by using:
curl --anyauth --user username:password http://someserver/site
I've seen references to being able to use the NTLM Authorization Proxy Server to get around these types of problems.
use --auth-no-challenge option (wget 1.11+) (it's now considered unsafe)
I found solution.
It is work-around for Basic auth IIS7.
When auth is successeful it send next http header:
'Authorization: < type > < credentials >'.
So we able to do authorization in browser and
copy this header params from browser (firebug addon) or generate:
$ echo -en 'username:password' | base64
dXNlcm5hbWU6cGFzc3dvcmQK
$ echo 'dXNlcm5hbWU6cGFzc3dvcmQK' | base64 -d
username:password
example:
$ wget --header="Authorization: Basic dXNlcm5hbWU6cGFzc3dvcmQK" http://example.com/