Giter VIP home page Giter VIP logo

scala-nsq's People

Contributors

mitallast avatar

Watchers

 avatar  avatar  avatar

Forkers

keenworks

scala-nsq's Issues

Client listener?

I'm having trouble figuring out how to create a simple scala app that creates an nsq consumer that is always running. Could you supply an example for that? I'm trying to create a sample app that just listens for nsq messages, transforms them, and puts them on a different nsq topic. Right now my object is just extending scala.App since I'm not sure how else to do it, and the app of course closes immediately after starting up. What's the normal way of creating an actual listener out of this that stays running until the app is shut down?

(Is it possible to turn it into an akka-streams Source?)

  val client = NSQClient()

  val producer = client.producer()

  val listener: Try[OK] => Unit = {
    case Success(_: OK) => log.info("message pub successfully")
    case Failure(error) => log.info("message pub failed", error)
  }

  // publish one message
  producer.pub(topic="test", data=Array[Byte](1,0,1,1)).onComplete(listener)
  producer.pubStr(topic="test", data="hello").onComplete(listener)

  // By default: http://127.0.0.1:4161
  val consumer: NSQConsumer = client.consumer(topic="test", channel="default") { msg =>
    log.info("received: {}", msg)
    // send `TOUCH msgid` message request
    msg.touch()
    // send `REQ msdid 100` message request
//    msg.req(100 milliseconds)
    // send `FIN msgid` message request
    msg.fin()
  }

Defining nodes for publish operations

Hey, I was playing with the lib and noticed something with the logic around selecting nodes to which to publish. The default functionality seems to do the following:

  • query lookup servers provided in constructor
  • provides a list of all the list of producers registered with those lookup servers
  • randomly selects one of the producers
  • publishes to it

This seems to be fairly different to how nsqd is designed to work, which is to have nsqd running locally and publish only to it.

Is this an intentional design choice on your part? I mean, if one knows about this functionality, it's simple enough to write a custom NSQLookup class to provide explicit addresses in the response from nodes() (which is what we'll be doing), but since the default behavior is considerably different to the intended design of NSQ, you may want to consider adding more documentation around this point so others are not surprised. If you'd like, I can take a stab at writing some of that.

Thanks!

Exception IllegalArgumentException: bound must be positive

Using config

nsq {
  lookup-address = [
    "http://127.0.0.1:xxxx"
  ]
}
[error] (run-main-1e) java.lang.IllegalArgumentException: bound must be positive
java.lang.IllegalArgumentException: bound must be positive
	at java.util.Random.nextInt(Random.java:388)
	at scala.util.Random.nextInt(Random.scala:66)
	at com.github.mitallast.nsq.NSQNettyClient$NSQNettyPool$class.connection(NSQNettyClient.scala:532)
	at com.github.mitallast.nsq.NSQNettyClient$NSQNettyProducer.connection(NSQNettyClient.scala:650)
	at com.github.mitallast.nsq.NSQNettyClient$NSQNettyProducer.pub(NSQNettyClient.scala:664)
	at com.github.mitallast.nsq.NSQProducer$class.pubStr(NSQClient.scala:55)
	at com.github.mitallast.nsq.NSQNettyClient$NSQNettyProducer.pubStr(NSQNettyClient.scala:650)
	at com.company.Main$.main(Main.scala:27)
	at com.company.Main.main(Main.scala)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)

I am getting Exception. I tried debugging the code as well.and it turns out poolMap never gets initialized.

private val poolMap = new AbstractChannelPoolMap[SocketAddress, FixedChannelPool]

Am i missing something. Please suggest.

Support for Scala 2.12.x

Are there any plans to support Scala version 2.12.x? I've cloned the repo, manually compiled against 2.12.2, and run the app and it seems to work properly. Are there any considerations about which you're concerned?

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.