-2
import com.solacesystems.jcsmp.BytesXMLMessage;
import com.solacesystems.jcsmp.JCSMPException;
import com.solacesystems.jcsmp.JCSMPFactory;
import com.solacesystems.jcsmp.JCSMPProperties;
import com.solacesystems.jcsmp.JCSMPRequestTimeoutException;
import com.solacesystems.jcsmp.JCSMPSession;
import com.solacesystems.jcsmp.JCSMPStreamingPublishEventHandler;
import com.solacesystems.jcsmp.Requestor;
import com.solacesystems.jcsmp.TextMessage;
import com.solacesystems.jcsmp.Topic;
import com.solacesystems.jcsmp.XMLMessageConsumer;
import com.solacesystems.jcsmp.XMLMessageListener;
import com.solacesystems.jcsmp.XMLMessageProducer;

public class REquestor {

public static void main(String... args) throws JCSMPException {
    // Check command line arguments
    String host="tcp://52.76.233.76:55555";
    String username="ccs_jcsmp_user_ccs3";
    String pwd="password";
    String vpn="default";

    System.out.println("BasicRequestor initializing...");

    // Create a JCSMP Session
    final JCSMPProperties properties = new JCSMPProperties();
    properties.setProperty(JCSMPProperties.HOST, host);     // host:port
    properties.setProperty(JCSMPProperties.USERNAME, username); // client-username
    properties.setProperty(JCSMPProperties.PASSWORD, pwd); // client-password
    properties.setProperty(JCSMPProperties.VPN_NAME,  vpn); // message-vpn
    final JCSMPSession session =  JCSMPFactory.onlyInstance().createSession(properties);
    session.connect();

    //This will have the session create the producer and consumer required
    //by the Requestor used below.

    /** Anonymous inner-class for handling publishing events */
    @SuppressWarnings("unused")
    XMLMessageProducer producer = session.getMessageProducer(new JCSMPStreamingPublishEventHandler() {

        public void responseReceived(String messageID) {
            System.out.println("Producer received response for msg: " + messageID);
        }

        public void handleError(String messageID, JCSMPException e, long timestamp) {
            System.out.printf("Producer received error for msg: %s@%s - %s%n",
                    messageID,timestamp,e);
        }
    });

    XMLMessageConsumer consumer = session.getMessageConsumer((XMLMessageListener)null);
//        final XMLMessageConsumer consumer = session.getMessageConsumer(new     XMLMessageListener() {
//
//            public void onReceive(BytesXMLMessage reply) {
//
//                System.out.printf("TextMessage reply received: '%s'%n",((TextMessage)reply).getText());
//
//            }
//
//            public void onException(JCSMPException e) {
//                System.out.printf("Consumer received exception: %s%n", e);
//            }
//        });
//        consumer.
    consumer.start();

    final Topic topic = JCSMPFactory.onlyInstance().createTopic("topicAnkit");

    //Time to wait for a reply before timing out
    final int timeoutMs = 100000;
    TextMessage request = JCSMPFactory.onlyInstance().createMessage(TextMessage.class);
    final String text = "Sample Request from Java!";
    request.setText(text);

    try {
        Requestor requestor = session.createRequestor();
        System.out.printf("Connected. About to send request message '%s' to topic '%s'...%n",text,topic.getName());
        BytesXMLMessage reply = requestor.request(request, timeoutMs, topic);

        // Process the reply
        if (reply instanceof TextMessage) {
            System.out.printf("TextMessage response received: '%s'%n",
                    ((TextMessage)reply).getText());
        }
        System.out.printf("Response Message Dump:%n%s%n",reply.dump());
    } catch (JCSMPRequestTimeoutException e) {
        System.out.println("Failed to receive a reply in " + timeoutMs + " msecs");
    }

    System.out.println("Exiting...");
    session.closeSession();
}
}

So my requirement is I am going to send message to "TopicAnkit" and listen for response in some topic/queue "topicResponse". How to achieve this? I see in my C++ replier I receive the request and send the reply to this program but this Java Requester is not listening to any topics. I see a temp topic is created in sendTo field to requester and sending is success but requester not getting the response. Please advice 1. How to get the response in Java requester from this temp topic 2. How to specify a listening topic so that C++ can send the response to this topic.

Thanks Ankit

user4581301
  • 33,082
  • 7
  • 33
  • 54
Ankit Saha
  • 19
  • 4
  • I have downvoted this question because there is far too much code here. In order to make it clear exactly where your problem is, please remove any code that is not directly causing your problem, and if you can reduce it to ten lines or less, I will consider retracting the downvote. See: [How to create a Minimal, Complete, and Verifiable example](http://stackoverflow.com/help/mcve) and [How to Debug Small Programs](https://ericlippert.com/2014/03/05/how-to-debug-small-programs/) – Joe C Nov 24 '17 at 06:09
  • Unrelated: Save yourself a bit of trouble. Rather than calling the default constructor and then setting all of the parameters the hard way, call `JCSMPProperties(String host, int port, String username, String password, SecureSessionProperties secureProps)` and get it all done in one shot. – user4581301 Nov 24 '17 at 06:13
  • I'm removing the C++ tag because it has no bearing on the question that I can see. – user4581301 Nov 24 '17 at 06:16
  • I added C++ because the Java code is working when both requester and replier are in Java. Only in case of Java(requester) and C++(Replier), the problem exists. – Ankit Saha Nov 24 '17 at 06:29
  • @JoeC Can you provide me an sample example of how to create a java Requester with C++ Replier sample solution? – Ankit Saha Nov 24 '17 at 08:37

2 Answers2

0

You don't seem to be explicitly setting which reply topic you want to use.

It can either be set on the message, or on the session, see https://docs.solace.com/API-Developer-Online-Ref-Documentation/java/com/solacesystems/jcsmp/Requestor.html

Add

final Topic responseTopic = JCSMPFactory.onlyInstance().createTopic("responseTopic");

request.setReplyTo(responseTopic);

before sending the message

Mic Hussey
  • 41
  • 2
0

Check message CorrelationId and ReplyTo.

As per solace API documentation don't forget about "#":

Requestor uses CorrelationId values starting with '#' which are reserved for internal use such as two party request/reply. If other applications are required to receive the reply, specify an application CorrelationId.

rink.attendant.6
  • 44,500
  • 61
  • 101
  • 156