Git Product home page Git Product logo

supernova's Introduction

supernova

CI Status

โš ๏ธ it is still very much under development ๐Ÿšง so use it at your own risk โš ๏ธ

A supernova is a powerful and luminous stellar explosion. This transient astronomical event occurs during the last evolutionary stages of a massive star or when a white dwarf is triggered into runaway nuclear fusion. The original object, called the progenitor, either collapses to a neutron star or black hole, or is completely destroyed. The peak optical luminosity of a supernova can be comparable to that of an entire galaxy before fading over several weeks or months.

supernova

Quick Start

The example located in test/Main.hs showcases a consumer & producer running concurrently (needs the async library).

main :: IO ()
main = runPulsar conn $ do
  c <- newConsumer topic sub
  p <- newProducer topic
  liftIO $ program c p

conn :: PulsarConnection
conn = connect defaultConnectData

topic :: Topic
topic = defaultTopic "app"

sub :: Subscription
sub = Subscription Exclusive "test-sub"

program :: Consumer IO -> Producer IO -> IO ()
program Consumer {..} Producer {..} =
  let c = fetch >>= \(Message i m) -> msgDecoder m >> ack i >> c
      p = sleep 3 >> traverse_ send messages >> p
  in  concurrently_ c p

A Message contains a MessageID you need for acking and a payload defined as a lazy ByteString.

Note that we wait a few seconds before publishing a message to make sure the consumer is already subscribed. Otherwise, it might miss some messages.

Run it with the following command:

cabal new-run supernova-tests

By default, it logs to the standard output in DEBUG level. You can change it by suppling LogOptions to the alternative function runPulsar'.

runPulsar' :: LogOptions -> PulsarConnection -> Pulsar a -> IO ()

Streaming

Since both consumers and producers operate on any MonadIO m, we could leverage some streaming libraries. Here's the same example using streamly.

import           Streamly
import qualified Streamly.Prelude              as S

program :: Consumer IO -> Producer IO -> IO ()
program Consumer {..} Producer {..} =
  let c = fetch >>= \(Message i m) -> msgDecoder m >> ack i >> c
      p = sleep 3 >> traverse_ send messages >> p
  in  S.drain . asyncly . maxThreads 10 $ S.yieldM c <> S.yieldM p

Development

It is recommended to use Cachix to reduce the compilation time.

nix-build

Or within a Nix shell (run nix-shell at the project's root).

cabal new-build

Generate Hackage tarball

cabal new-sdist

Upload documentation

cabal new-haddock --haddock-for-hackage --enable-doc
cabal upload -d dist-newstyle/supernova-0.0.2-docs.tar.gz --publish

supernova's People

Contributors

gvolpe avatar spatchkaa avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

supernova's Issues

Ensure messages sent are delivered

Whenever there's a single publisher that publishes a few messages (like in the demo) and then shuts down, we need to ensure (hello bracket) that the messages are delivered before we close the connection.

Right now, if we don't put a threadDelay, not all the messages are delivered.

Protobuf should not be a concern for users

In v0.0.1, users that pull in supernova need to add the protobuf dependency required by proto-lens-protoc.

We should split the code generation from the main module to avoid this dependency.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.