babashka

https://github.com/babashka/babashka. Also see #sci, #nbb and #babashka-circleci-builds .
2021-06-21T06:48:30.126300Z

Hi. I have a requirement to periodically push data into kafka topic in batches. If its a one time run, i could have directly run it in with bb script only construct the data. But since i need to run on a periodic basis, i need to push to kafka through bb script. But i keep running into dependency problems with every clojure jar i use. The java import

(import '[org.apache.kafka.clients.producer KafkaProducer ProducerRecord])
also didnt help. Can anyone help me out with this. Is it possible to use babashka for kafka

lispyclouds 2021-06-21T07:18:18.126400Z

Hey @kspriyan31 so the lib you're using is written in Java and bb is meant for primarily interpreting clojure code and not java byte codes. Some of the java classes have been baked into bb builds for convenience and to help out libs but not the Kafka one.

lispyclouds 2021-06-21T07:19:32.126600Z

The way you're expecting to use wont be possible in bb unless we compile bb with it being baked in. I had a similar need once and gotten around by shelling out to https://github.com/deviceinsight/kafkactl and sending things. Not so smooth but gets the job done

2021-06-21T07:19:51.127Z

I tried adding various clojure dependencies too @rahul080327. It gets errored out for missing dependencies

2021-06-21T07:20:12.127200Z

Is there any kafka client library that is compatible wiht babashka

lispyclouds 2021-06-21T07:20:43.127400Z

Most of the kafka libs are wrappers around the canonical java lib and we need to bake that in to make it work like you want

2021-06-21T07:21:19.127600Z

Thanks @rahul080327. That helps.

lispyclouds 2021-06-21T07:21:51.127800Z

as far as i know, none of the popular libs would work, unless they somehow implement in pure clojure, still there could be issues

2021-06-21T07:23:39.128Z

Yes. thats exactly what happened. Thanks for your help. I will try to approach with a different solution

lispyclouds 2021-06-21T07:25:16.128200Z

kafkactl with babashka.process sort of solved my usecase, which was quite simple though ๐Ÿ˜„

2021-06-21T07:26:09.128500Z

Cool thanks. Will give it a go

lispyclouds 2021-06-21T07:27:22.128700Z

you could also implement it as a Pod: https://book.babashka.org/#pods Would be a really useful one! ๐Ÿ˜„

๐Ÿ‘ 1
borkdude 2021-06-21T07:38:20.129100Z

There is a pod here: https://github.com/tzzh/pod-tzzh-kafka But it doesn't have any releases yet. @thomas.ormezzano?

lispyclouds 2021-06-21T07:39:00.129500Z

ah nice!

2021-06-21T07:39:49.129700Z

nice. thanks @borkdude. will try it out

2021-06-21T07:56:09.129900Z

yeah @borkdude there is no manifest available for this

borkdude 2021-06-21T07:58:13.130100Z

There is no manifest because there is no release

๐Ÿ‘ 1
borkdude 2021-06-21T07:58:26.130400Z

You could try to compile it locally

borkdude 2021-06-21T07:58:46.130700Z

and then load it with (load-pod "my-local-binary")

2021-06-23T05:10:53.162300Z

There were errors while compiling it. unable to create a binary from it

lispyclouds 2021-06-23T06:03:48.162500Z

How did you try to compile it @kspriyan31?

lispyclouds 2021-06-23T06:04:07.162700Z

just cloned and ran go build seems to compile for me

2021-06-23T06:19:42.162900Z

Did the same actually

lispyclouds 2021-06-23T06:22:51.163100Z

what errors do you see?

lispyclouds 2021-06-23T06:23:34.163300Z

also what's your go version?

2021-06-23T06:25:42.163500Z

# <http://gopkg.in/confluentinc/confluent-kafka-go.v1/kafka|gopkg.in/confluentinc/confluent-kafka-go.v1/kafka>
In file included from ..\..\go\pkg\mod\<http://gopkg.in|gopkg.in>\confluentinc\confluent-kafka-go.v1@v1.4.2\kafka\00version.go:24:
./librdkafka/rdkafka.h:83:10: fatal error: sys/socket.h: No such file or directory
   83 | #include &lt;sys/socket.h&gt; /* for sockaddr, .. */
      |          ^~~~~~~~~~~~~~
compilation terminated.

2021-06-23T06:25:46.163700Z

go version go1.16.5 windows/amd64

lispyclouds 2021-06-23T06:31:37.163900Z

so it seems librdkafka, the c lib powering the confluent connector isnt supported on windows

lispyclouds 2021-06-23T06:34:17.164100Z

could you try the steps mentioned here: https://github.com/confluentinc/confluent-kafka-go/issues/128

lispyclouds 2021-06-23T06:34:52.164400Z

basically you need to have MinGW gcc installed

lispyclouds 2021-06-23T06:35:04.164600Z

if thats there, the compile may work

lispyclouds 2021-06-23T06:35:33.164800Z

alternatively you could try using Windows Subsystem Linux

tzzh 2021-06-23T13:59:01.165Z

Hey guys yeah sorry there is no release as it's using CGO (ie C extensions for go) and so it's harder to cross compile it (I didn't know about the issues about confluent-kafka-go on windows but I guess that makes it even harder)

borkdude 2021-06-23T15:14:12.170300Z

@thomas.ormezzano We have a pod which is using CGO here: https://github.com/babashka/pod-babashka-go-sqlite3 If you want, you can copy the configs :)

tzzh 2021-06-23T15:44:21.170800Z

nice, thanks ๐Ÿ™‚ I'll try to take a look when I have a bit more time

stijn 2021-06-21T08:23:33.131200Z

is this intended behavior?

{:tasks {repro {:doc (str "This tasks repro is: " "showing a doc string")
                :task (shell "ls")}}}

stijn 2021-06-21T08:23:55.131600Z

โฏ bb tasks
The following tasks are available:

repro (str "This tasks repro is: " "showing a doc string")

stijn 2021-06-21T08:24:50.132600Z

I'm trying to build a doc string from some default values, but it interprets the value of :doc literally

borkdude 2021-06-21T08:25:19.133100Z

Currently the docstring isn't evaluated, except those on functions, if you refer to them with :task foo.bar/baz

borkdude 2021-06-21T08:25:35.133400Z

I mean, then the docstring is picked from the function

stijn 2021-06-21T08:25:41.133600Z

I see

borkdude 2021-06-21T08:26:00.134Z

We could change that, this is just currently how it works

borkdude 2021-06-21T08:26:41.135100Z

it's a bit difficult to decide how to evaluate those string args though

stijn 2021-06-21T08:26:57.135800Z

yeah, it would come in handy, but looking at most commandline tools that support 'actions', the overview doesn't give a lot of detail, and only does so when you would bb repro --help

borkdude 2021-06-21T08:26:58.135900Z

because it may refer to things depending on previous tasks etc

stijn 2021-06-21T08:27:49.136600Z

ok, no worries. I can work with this, was just wondering if this was intended behavior

stijn 2021-06-21T08:28:22.137200Z

thanks for babashka tasks by the way, it's super awesome for writing dev tooling

๐Ÿ‘ 1
โค๏ธ 1
bocaj 2021-06-21T17:02:24.140200Z

Iโ€™m looking at this libary to do consistent hashing https://github.com/replikativ/hasch. The lib has a platform ns: (:import java.io.ByteArrayOutputStream java.nio.ByteBuffer java.security.MessageDigest) . Are these dependencies under consideration?

bocaj 2021-06-21T17:03:18.141300Z

Or, any more bash-like idea for consistent hashing? Iโ€™m simply trying to cache which rows/objects/maps have been already processed in a data pipeline.

bocaj 2021-06-21T17:03:44.141600Z

I like hasch b/c itโ€™s very thorough.

borkdude 2021-06-21T17:34:08.141900Z

I think these classes might already be in bb

bocaj 2021-06-21T17:34:58.142400Z

digging into the code, the lib uses protocols as well: thatโ€™s the larger hurdle, right?

borkdude 2021-06-21T17:35:10.142700Z

protocols are also supported in bb

bocaj 2021-06-21T17:35:14.143Z

oh! great

borkdude 2021-06-21T17:35:22.143300Z

just try out the library, you'll likely run into something else ;)

bocaj 2021-06-21T17:35:31.143500Z

indeed.

bocaj 2021-06-21T17:36:20.144100Z

If I hunt in here: https://github.com/babashka/babashka/blob/master/src/babashka/impl/classes.clj and donโ€™t e.g. ByteArrayOutputStream then itโ€™s not in bb, yet. Correct?

bocaj 2021-06-21T17:36:57.144800Z

ah, but it is there. https://github.com/babashka/babashka/blob/d90f4e7bacb0af902764f66be4ba0255528d795c/src/babashka/impl/classes.clj#L93 Well, thanks for your help anyway!

borkdude 2021-06-21T17:37:09.145500Z

Let's talk in a thread.

borkdude 2021-06-21T17:37:21.145700Z

borkdude@MBP2019 /tmp $ export BABASHKA_CLASSPATH=$(clojure -Spath -Sdeps '{:deps {io.replikativ/hasch {:mvn/version "0.3.7"}}}')
borkdude@MBP2019 /tmp $ bb -e "(use 'hasch.core)"
----- Error --------------------------------------------------------------------
Type:     clojure.lang.ExceptionInfo
Message:  Unable to resolve classname: java.io.FileInputStream
Location: hasch/platform.clj:162:24
Phase:    analysis

----- Context ------------------------------------------------------------------
158:   java.io.File
159:   (-coerce [f md-create-fn write-handlers]
160:     (let [^MessageDigest md (md-create-fn)
161:           len (.length f)]
162:       (with-open [fis (java.io.FileInputStream. f)]
                            ^--- Unable to resolve classname: java.io.FileInputStream
163:         (encode (:binary magics)
164:                 ;; support default split-size behaviour transparently
165:                 (if (&lt; len split-size)
166:                   (let [ba (with-open [out (java.io.ByteArrayOutputStream.)]
167:                              (<http://clojure.java.io/copy|clojure.java.io/copy> fis out)

borkdude 2021-06-21T17:37:43.145900Z

I think we can just add that class.

bocaj 2021-06-21T17:38:27.146100Z

Is there a way for me to quickly add, and iterate through all the dependencies?

borkdude 2021-06-21T17:39:08.146300Z

yeah, you can clone babashka and invoke it using clojure -M:babashka/dev ... when you make an alias for it, that's how I do it

๐Ÿ™ 1
bocaj 2021-06-21T17:39:18.146500Z

ok

borkdude 2021-06-21T17:40:46.146800Z

After adding that class, it appears to work

borkdude 2021-06-21T17:40:59.147Z

$ clojure -M:babashka/dev -e "(use 'hasch.core) (uuid5 (edn-hash \"hello world\"))"
#uuid "1227fe0a-471b-5329-88db-875fb82737a8"

bocaj 2021-06-21T17:41:34.147200Z

great!

borkdude 2021-06-21T17:42:17.147400Z

I will commit to master. New binary will appear in #babashka-circleci-builds in a few minutes

bocaj 2021-06-21T17:44:15.147600Z

wow

borkdude 2021-06-21T17:55:37.147800Z

@bocaj ok, it's there now and it seems to work.

$ bb -e "(use 'hasch.core) (edn-hash [\"hello world\" {:a 3.14} #{42} '(if true nil \f)])"
(245 139 93 212 32 95 155 217 230 42 204 224 210 124 22 156 241 230 65 199 21 108 160 143 225 185 228 16 141 66 80 96 35 189 202 198 252 99 12 214 23 106 43 113 138 129 16 131 7 110 102 1 55 15 4 148 118 187 201 28 144 90 192 21)

bocaj 2021-06-21T17:57:49.148Z

Thanks, again! Do you do windows builds each release?

bocaj 2021-06-21T17:59:36.148400Z

wow, again

bocaj 2021-06-21T18:00:04.148600Z

So glad this is all in the open, I have lots to learn.

borkdude 2021-06-21T18:13:10.148800Z

@bocaj To be clear, you can just download the binary from appveyor and test it out, right now

borkdude 2021-06-21T18:13:25.149Z

You don't have to wait for a release and you can do some testing pre-release if you want

bocaj 2021-06-21T18:17:48.149200Z

Yes, I assumed that. Itโ€™s working on my mac.

bocaj 2021-06-21T18:19:26.149400Z

I have a windows server, so Iโ€™ll check that later. Safe to assume windows binary always works out?

borkdude 2021-06-21T18:20:01.149600Z

Just to be sure, I'll add hasch's unit tests to babashka's CI later this week. Those tests also run on Windows CI

borkdude 2021-06-21T18:20:12.149800Z

but usually there aren't any Windows-specific problems

๐Ÿ‘ 1
borkdude 2021-06-21T19:59:39.150100Z

I added all tests to CI now. They are all passing, except around hashing records like (defrecord Foo []). This is because records are implemented differently in bb.