-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added some producer and consumer code going to run activemq
- Loading branch information
1 parent
26c85bc
commit 2be0ff3
Showing
7 changed files
with
233 additions
and
0 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<classpath> | ||
<classpathentry kind="src" path="src"/> | ||
<classpathentry kind="con" path="org.scala-ide.sdt.launching.SCALA_CONTAINER"/> | ||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/> | ||
<classpathentry kind="lib" path="/opt/apache-activemq-5.14.1/activemq-all-5.14.1.jar"/> | ||
<classpathentry kind="output" path="bin"/> | ||
</classpath> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
/bin/ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<projectDescription> | ||
<name>ScalaChatApp</name> | ||
<comment></comment> | ||
<projects> | ||
</projects> | ||
<buildSpec> | ||
<buildCommand> | ||
<name>org.scala-ide.sdt.core.scalabuilder</name> | ||
<arguments> | ||
</arguments> | ||
</buildCommand> | ||
</buildSpec> | ||
<natures> | ||
<nature>org.scala-ide.sdt.core.scalanature</nature> | ||
<nature>org.eclipse.jdt.core.javanature</nature> | ||
</natures> | ||
</projectDescription> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
eclipse.preferences.version=1 | ||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled | ||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8 | ||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve | ||
org.eclipse.jdt.core.compiler.compliance=1.8 | ||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate | ||
org.eclipse.jdt.core.compiler.debug.localVariable=generate | ||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate | ||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error | ||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error | ||
org.eclipse.jdt.core.compiler.source=1.8 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import javax.jms._ | ||
import org.apache.activemq.ActiveMQConnection | ||
import org.apache.activemq.ActiveMQConnectionFactory | ||
|
||
|
||
object Consumer { | ||
val url = "tcp://localhost:61616" | ||
val topic = "chatroom" | ||
|
||
def main(args: Array[String]) | ||
{ | ||
val connectionFactory = new ActiveMQConnectionFactory(url) | ||
val connection = connectionFactory.createConnection | ||
//connection.setClientID("ConsumerSynchronous") | ||
connection.start() | ||
|
||
println("Started") | ||
|
||
val session: Session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE) | ||
//val queue = session.createQueue("SendSynchronousMsgQueue") | ||
val destination: Topic = session.createTopic(this.topic) | ||
val consumer: MessageConsumer = session.createConsumer(destination) | ||
|
||
val listener = new MessageListener { | ||
def onMessage(message: Message) { | ||
message match { | ||
case text: TextMessage => { | ||
//val replyProducer = session.cr | ||
//replyProducer.setDeliveryMode(DeliveryMode.NON_PERSISTENT) | ||
|
||
println("Received message: " + text.getText) | ||
|
||
//val replyMessage = session.createTextMessage("Yes I received your message!") | ||
//replyMessage.setJMSCorrelationID(text.getJMSCorrelationID()) | ||
|
||
//println("Reply sent!") | ||
|
||
//replyProducer.send(replyMessage) | ||
} | ||
case _ => { | ||
throw new Exception("Unhandled Message Type: " + message.getClass.getSimpleName) | ||
} | ||
} | ||
} | ||
} | ||
consumer.setMessageListener(listener) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
import org.apache.activemq.ActiveMQConnection; | ||
import org.apache.activemq.ActiveMQConnectionFactory | ||
import javax.jms._ | ||
import java.util.Scanner | ||
object Producer { | ||
val url: String = "tcp://localhost:61616" | ||
val topicName: String = "chatroom" | ||
|
||
def main(args:Array[String]) | ||
{ | ||
val input: Scanner = new Scanner(System.in) | ||
val connectionFactory: ConnectionFactory = new ActiveMQConnectionFactory(url) | ||
val connection: Connection = connectionFactory.createConnection | ||
connection.start | ||
val session: Session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE) | ||
val destination: Topic = session.createTopic(topicName) | ||
val messageProducer: MessageProducer = session.createProducer(destination) | ||
val textMessage: TextMessage = session.createTextMessage("Hello Subscriber!") | ||
while(true) { | ||
val userMessage = input.nextLine() | ||
textMessage.setText(userMessage) | ||
messageProducer.send(textMessage) | ||
println("Message sent to subscriber: '" + textMessage.getText + "'") | ||
} | ||
connection.close | ||
|
||
} | ||
} |