I'm adding rabbitmq to my yesod application and based off the documentation(at the bottom) It looks like I'm supposed to open a new channel per thread which means a new channel per request in yesod. From what I can tell, my two options to add this are using wai middleware or yesod middleware. In a WAI request I can use Vault to store arbitrary values like this. I'm wondering if Vault
is the way to go or if I should be adding this at a higher level somewhere in a YesodRequest
, and if so where?
Asked
Active
Viewed 77 times
0
-
So not every request needs a RabbitMQ connection (that'll cause way too many connections to RabbitMQ most likely). Typically you would have a pool of connections stored in your `App` datatype, and requests would withdraw a connection if they need it (and return it when they're done). This is the model followed by Persistent (`appConnPool` in the scaffolding). You can see this approach with Redis [in this blog post](http://maxgabriel.github.io/redis-yesod/). I don't have experience with Haskell's RabbitMQ package but I think you would want a setup like that. – MaxGabriel Apr 15 '16 at 03:09
-
If you're just developing something simple, it looks like you don't *have* to do this, since the amqp package docs say: "It is recommended to use a separate channel for each thread in your application that talks to the AMQP server (but you don't have to as channels are thread-safe)". – MaxGabriel Apr 15 '16 at 03:11
-
I haven't used it before, but it looks like both Persistent and Hedis use the [`resource-pool`](https://hackage.haskell.org/package/resource-pool) package to create connection pools. – MaxGabriel Apr 15 '16 at 03:15
-
I won't create multiple *connections* only 1 connection is necessary but I would (maybe?) need multiple *channels*. I've read conflicting information about the thread safety of channels. It seems like for some operations they're thread safe and other operations they're not. – jvans Apr 15 '16 at 12:27