mitallast / scala-nsq Goto Github PK
View Code? Open in Web Editor NEWNSQ client library on scala, based on netty
License: MIT License
NSQ client library on scala, based on netty
License: MIT License
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()
}
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:
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!
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.
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?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.