Guest User

Untitled

a guest
Jul 13th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.14 KB | None | 0 0
  1. TopicSubscriber initializing...
  2. Jul 12, 2018 2:27:56 PM com.solacesystems.jcsmp.protocol.impl.TcpClientChannel call
  3. INFO: Connecting to host 'blocked out' (host 1 of 1, smfclient 2, attempt 1 of 1, this_host_attempt: 1 of 1)
  4. Jul 12, 2018 2:28:17 PM com.solacesystems.jcsmp.protocol.impl.TcpClientChannel call
  5. INFO: Connection attempt failed to host 'blocked out' ConnectException com.solacesystems.jcsmp.JCSMPTransportException: ('blocked out') - Error communicating with the router. cause: java.net.ConnectException: Connection timed out: no further information ((Client name: 'blocked out' Local port: -1 Remote addr: 'blocked out') - )
  6. Jul 12, 2018 2:28:20 PM com.solacesystems.jcsmp.protocol.impl.TcpClientChannel close
  7. INFO: Channel Closed (smfclient 2)
  8. Exception in thread "main" com.solacesystems.jcsmp.JCSMPTransportException" (Client name: 'blocked out' Local port: -1 Remote addr: 'blocked out') - Error communicating with the router.
  9.  
  10. import java.util.concurrent.CountDownLatch;
  11.  
  12. import com.solacesystems.jcsmp.BytesXMLMessage;
  13. import com.solacesystems.jcsmp.JCSMPException;
  14. import com.solacesystems.jcsmp.JCSMPFactory;
  15. import com.solacesystems.jcsmp.JCSMPProperties;
  16. import com.solacesystems.jcsmp.JCSMPSession;
  17. import com.solacesystems.jcsmp.TextMessage;
  18. import com.solacesystems.jcsmp.Topic;
  19. import com.solacesystems.jcsmp.XMLMessageConsumer;
  20. import com.solacesystems.jcsmp.XMLMessageListener;
  21.  
  22. public class TopicSubscriber {
  23.  
  24. public static void main(String... args) throws JCSMPException {
  25.  
  26. // Check command line arguments
  27. if (args.length != 3 || args[1].split("@").length != 2) {
  28. System.out.println("Usage: TopicSubscriber <host:port> <client-username@message-vpn> <client-password>");
  29. System.out.println();
  30. System.exit(-1);
  31. }
  32. if (args[1].split("@")[0].isEmpty()) {
  33. System.out.println("No client-username entered");
  34. System.out.println();
  35. System.exit(-1);
  36. }
  37. if (args[1].split("@")[1].isEmpty()) {
  38. System.out.println("No message-vpn entered");
  39. System.out.println();
  40. System.exit(-1);
  41. }
  42.  
  43. System.out.println("TopicSubscriber initializing...");
  44. final JCSMPProperties properties = new JCSMPProperties();
  45. properties.setProperty(JCSMPProperties.HOST, args[0]); // host:port
  46. properties.setProperty(JCSMPProperties.USERNAME, args[1].split("@")[0]); // client-username
  47. properties.setProperty(JCSMPProperties.PASSWORD, args[2]); // client-password
  48. properties.setProperty(JCSMPProperties.VPN_NAME, args[1].split("@")[1]); // message-vpn
  49. final Topic topic = JCSMPFactory.onlyInstance().createTopic("tutorial/topic");
  50. final JCSMPSession session = JCSMPFactory.onlyInstance().createSession(properties);
  51.  
  52. session.connect();
  53.  
  54. final CountDownLatch latch = new CountDownLatch(1); // used for
  55. // synchronizing b/w threads
  56. /** Anonymous inner-class for MessageListener
  57. * This demonstrates the async threaded message callback */
  58. final XMLMessageConsumer cons = session.getMessageConsumer(new XMLMessageListener() {
  59. @Override
  60. public void onReceive(BytesXMLMessage msg) {
  61. if (msg instanceof TextMessage) {
  62. System.out.printf("TextMessage received: '%s'%n",
  63. ((TextMessage) msg).getText());
  64. } else {
  65. System.out.println("Message received.");
  66. }
  67. System.out.printf("Message Dump:%n%s%n", msg.dump());
  68. latch.countDown(); // unblock main thread
  69. }
  70.  
  71. @Override
  72. public void onException(JCSMPException e) {
  73. System.out.printf("Consumer received exception: %s%n", e);
  74. latch.countDown(); // unblock main thread
  75. }
  76. });
  77. session.addSubscription(topic);
  78. System.out.println("Connected. Awaiting message...");
  79. cons.start();
  80. // Consume-only session is now hooked up and running!
  81.  
  82. try {
  83. latch.await(); // block here until message received, and latch will flip
  84. } catch (InterruptedException e) {
  85. System.out.println("I was awoken while waiting");
  86. }
  87. // Close consumer
  88. cons.close();
  89. System.out.println("Exiting.");
  90. session.closeSession();
  91. }
  92. }
Add Comment
Please, Sign In to add comment