Last active
August 13, 2016 00:28
-
-
Save zkendall/0e7ab3146b1f9b79c021249f49993587 to your computer and use it in GitHub Desktop.
Local Qpid Attempt
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
{ | |
"name": "Test Broker", | |
"modelVersion": "6.0", | |
"defaultVirtualHost": "default", | |
"authenticationproviders": [ | |
{ | |
"name": "testing", | |
"type": "Plain", | |
"secureOnlyMechanisms": [], | |
"users": [ | |
{ | |
"name": "guest", | |
"type": "managed", | |
"password": "guest" | |
} | |
] | |
} | |
], | |
"ports": [ | |
{ | |
"name": "AMQP", | |
"port": "35672", | |
"authenticationProvider": "testing", | |
"virtualhostaliases": [ | |
{ | |
"name": "defaultAlias", | |
"type": "defaultAlias" | |
}, | |
{ | |
"name": "hostnameAlias", | |
"type": "hostnameAlias" | |
}, | |
{ | |
"name": "nameAlias", | |
"type": "nameAlias" | |
} | |
] | |
} | |
], | |
"virtualhostnodes": [ | |
{ | |
"name": "default", | |
"type": "JSON", | |
"virtualHostInitialConfiguration": "{ \"type\" : \"Memory\",\"name\" : \"default\",\"modelVersion\" : \"6.0\"}" | |
} | |
] | |
} |
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
package com.testing; | |
import com.testing.amqp.QpidRunner; | |
import org.slf4j.Logger; | |
import org.slf4j.LoggerFactory; | |
import org.testng.annotations.Test; | |
import javax.jms.*; | |
import javax.naming.Context; | |
import javax.naming.NamingException; | |
import java.io.IOException; | |
import java.util.Hashtable; | |
import static org.testng.Assert.assertTrue; | |
public class RunQpidTest { | |
Logger log = LoggerFactory.getLogger(getClass()); | |
/** | |
* Tests running Qpid from unpacked files (ie, the target/ folder of a maven build.) | |
*/ | |
@Test(description = "This works.") | |
public void runFromFiles() throws IOException { | |
QpidRunner q = QpidRunner.create(); | |
try { | |
// Launches bin/qpid-server with the attached config.json | |
boolean result = q.startFully(); | |
assertTrue(result); | |
} finally { | |
q.stop(); | |
} | |
} | |
@Test(description = "This fails with JmsOperationTimedOutException") | |
public void connectJms() throws NamingException, JMSException, IOException { | |
log.info("Starting."); | |
QpidRunner q = QpidRunner.create(); | |
try { | |
// Launches bin/qpid-server with the attached config.json | |
boolean result = q.startFully(); | |
assertTrue(result); | |
Hashtable<Object, Object> env = new Hashtable<>(); | |
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.apache.qpid.jms.jndi.JmsInitialContextFactory"); | |
env.put("jms.clientID", "myClient"); | |
env.put("connectionfactory.myFactoryLookup", "amqp://localhost:35672"); | |
// env.put("connectionfactory.myFactoryLookup", | |
// "amqp://guest:guest@clientid/test?brokerlist='tcp://localhost:35672'"); | |
env.put("jms.username", "guest"); | |
env.put("jms.password", "guest"); | |
env.put("queue.myQueueLookup", "myQueue"); | |
env.put("destination.topicExchange", "myTopic"); | |
Context context = new javax.naming.InitialContext(env); | |
ConnectionFactory connectionFactory = (ConnectionFactory) context.lookup("myFactoryLookup"); | |
// NOTE: If I don't put in credentials here then I get: | |
// "javax.jms.JMSSecurityException: Could not find a suitable SASL mechanism for the remote peer using the available credentials." | |
Connection connection = connectionFactory.createConnection("guest", "guest"); | |
log.info("Starting connection."); | |
connection.start(); // XXX: FAILS | |
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); | |
Destination destination = (Destination) context.lookup("topicExchange"); | |
MessageProducer messageProducer = session.createProducer(destination); | |
MessageConsumer messageConsumer = session.createConsumer(destination); | |
TextMessage message = session.createTextMessage("Hello world!"); | |
messageProducer.send(message); | |
message = (TextMessage) messageConsumer.receive(); | |
System.out.println(message.getText()); | |
connection.close(); | |
context.close(); | |
} finally { | |
q.stop(); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment