0

Why i can not create a simple stomp client using the hornetq-core-client.2.2.21.Final.jar?

Map<String, Object> properties = new HashMap<String, Object>();
properties.put("host", "localhost");
properties.put("port", 61612);
properties.put("protocol", "stomp");
TransportConfiguration transportConfiguration = new TransportConfiguration(NettyConnectorFactory.class.getName(), properties);
ServerLocator serverLocator = HornetQClient.createServerLocatorWithoutHA(transportConfiguration);
ClientSessionFactory clientSessionFactory = serverLocator.createSessionFactory();
ClientSession clientSession = clientSessionFactory.createSession();
clientSession.createQueue("queue", "queue", true);
ClientProducer clientProducer = clientSession.createProducer("queue");
ClientMessage clientMessage = clientSession.createMessage(true);
clientMessage.getBodyBuffer().writeString("Hello");
clientProducer.send(clientMessage);

I get the following error:

java.lang.IllegalStateException: The following keys are invalid for configuring a connector: protocol

CelinHC
  • 1,857
  • 2
  • 27
  • 36

1 Answers1

0

You should use Stomp protocol for sending messages:

public void sendViaStomp(Serializable obj, String queueName) 
    {
        try 
        {
            Socket socket = new Socket("127.0.0.1",61612);

            String connectFrame = "CONNECT\n" +
                    "login: guest\n" +
                    "passcode: guest\n" + 
                    "request-id: 1\n" +
                    "\n"+
                    END_OF_FRAME;
            sendFrame(socket, connectFrame);

            String text = (String) obj;
            String messageFrame = "SEND\n" +
                    "destination: jms.queue." + queueName + "\n" +
                    "\n"+
                    text + 
                    END_OF_FRAME;
            sendFrame(socket, messageFrame);

            System.out.println("Sent Stomp Message:" + text);

            String disconnectFrame = "DISCONNECT\n" +
                    "\n" + 
                    END_OF_FRAME;
            sendFrame(socket, disconnectFrame);

            socket.close();
        } 
        catch (UnknownHostException e) 
        {
            e.printStackTrace();
        }
        catch (IOException e) 
        {
            e.printStackTrace();
        }
    }
private void sendFrame(Socket socket, String data)
    {
        byte[] bytes;
        try 
        {
            bytes = data.getBytes("UTF-8");
            OutputStream outputStream = socket.getOutputStream();
            for (int i = 0; i < bytes.length; i++)
            {
                outputStream.write(bytes[i]);
            }
            outputStream.flush();
        } 
        catch (UnsupportedEncodingException e)
        {
            e.printStackTrace();
        } 
        catch (IOException e)
        {
            e.printStackTrace();
        }
    }
Arya
  • 2,809
  • 5
  • 34
  • 56