Fork me on GitHub
#ring-swagger
<
2019-02-05
>
Empperi09:02:06

Trying to get compojure-api + aleph + core.async combo to work. Unfortunately my channels end up into compojure render phase and there cause an exception

Empperi09:02:14

Trying to figure out which part am I missing

Empperi09:02:38

I have required compojure.api.async so that it extends the necessary protocols

Empperi09:02:37

https://github.com/metosin/compojure-api/wiki/Async says that aleph needs manual bootstrapping. Is this still the case? This page has been updated in 2017

Empperi09:02:10

And if so, what that would actually mean?

Empperi09:02:24

I'm having hard time to understand what could possibly be needed

Empperi09:02:50

I mean, I have a fully working aleph server running, everything else works except async stuff

Empperi09:02:31

I would prefer using core.async since I need to do relatively complex concurrent querying which then will translate into the actual response which I'll return from my API

Empperi09:02:31

Guess I can just read the channel in a blocking manner just before I return something from my handlers but that sounds so lame...

Empperi13:02:54

The more I've dug into this the harder this problem seems to be. Now I've dumped Aleph and taken Jetty. Now I manage to serialize channels but unfortunately not via compojure-api but via my own system. However, what I've realized here is that it isn't strictly obvious how one should serialize the channel. For example, the main reason why channels are nice as response medium is that they can be written "as they come". So when it comes to JSON one should have one put operation per JSON array element. However, what if one wants to send just a JSON object without array wrapper? Should we just write an object if all we get from the channel is just one element? The answer is of course "no" since in that case we couldn't have one element long arrays which are definitely needed.

Empperi13:02:37

Yeah, I've seen that

Empperi13:02:53

Also, do you have an idea regarding the problem I described above? 🙂

Empperi13:02:06

Basically sounds to me like an unsolvable problem without some additional information

ikitommi13:02:53

oh, you would also need a streaming json writer

Empperi13:02:55

One could use spec definitions to deduce if the result should be an array or not

ikitommi13:02:33

do you have large data sets you need to return?

Empperi13:02:50

Yes and no. No right now, yes in the future

Empperi14:02:51

So I could just ignore it at this point

Empperi14:02:57

But that feels... Dirty 🙂

ikitommi14:02:23

if you need to stream data, I would use sse or web sockets and push separate full json data blobs out

Empperi14:02:35

And basically if I did that then the easiest solution would be just to consume the whole thing at handler level, do the serialization there etc since that's where I know what kind of structure the data should have

ikitommi14:02:10

writing a large json-array in parts would require to write the json internally in parts too.

ikitommi14:02:30

if the data is not big, just collect the bits via core.async and when it’s done, flush it out?

Empperi14:02:08

Yeah, that is practically the only thing I can think of which would make this in any way reasonable

Empperi14:02:14

Without excessive amount of work

Empperi14:02:35

Practically need to skip all the nice automatic conversions of compojure-api then though

Empperi14:02:50

or wait. Not really

ikitommi14:02:53

yeah, you can’t do things like validate the output if you stream out the data in parts etc.

Empperi14:02:52

Right. Need to push this to higher abstraction level and do the work there

ikitommi14:02:06

but, returning a stream of json parts is also a different contract to a returning a full data

ikitommi14:02:35

you can still validate the parts manually in the handler, if you would stream it out.

Empperi14:02:12

I have streaming use case right from the bat but fortunately it's a bit of a special case where I do not need to care about this stuff

Empperi14:02:33

Cheers. Needed some brain racking.

Empperi14:02:40

(flu, not at my best right now)