Thanks, It works! It works with the command ./standalone.sh -c standalone-full.xml, as we determine that the exactly this xml file is used.
Now I'm trying to connect with a client to my server, which I launched with hornetq: the Code is here:
SERVER:
@MessageDriven(name = "MessageMDBSample", activationConfig = {
@ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
@ActivationConfigProperty(propertyName = "destination", propertyValue = "queue/test"),
@ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge") })
public class QueueListenerMDB implements MessageListener {
public QueueListenerMDB() {
System.out.println("Constructor");
}
public void onMessage(Message message) {
try {
if (message instanceof TextMessage) {
System.out.println("Queue: I received a TextMessage at "
+ new Date());
TextMessage msg = (TextMessage) message;
System.out.println("Message is : " + msg.getText());
}
} catch (JMSException e) {
e.printStackTrace();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
I see my Queues in AdminConsole on Jboss Server, so the Server runs.
I cannot establish connection from the Client to the server, it tried a lot of possibility, maybe can you say, which of possibility is more or less in the right direction:
Variant1 :
public static void main(String[] args) throws Exception {
new JMSApplicationClient().firstConnection();
}
private void firstConnection() throws JMSException {
// Step 1. Directly instantiate the JMS Queue object.
Queue queue = HornetQJMSClient.createQueue("testQueue");
//Queue replyQueue = HornetQJMSClient.createQueue("replyQueue");
// Step 2. Instantiate the TransportConfiguration object
// which
// contains the knowledge of what transport to use,
// The server port etc.
Map connectionParams = new HashMap();
connectionParams
.put(org.hornetq.core.remoting.impl.netty.TransportConstants.PORT_PROP_NAME,
5445);
// connectionParams.put(Context.SECURITY_PRINCIPAL, "guest");
// connectionParams.put(Context.SECURITY_CREDENTIALS, "pass");
TransportConfiguration transportConfiguration = new TransportConfiguration(
NettyConnectorFactory.class.getName(), connectionParams);
// Step 3 Directly instantiate the JMS ConnectionFactory
// object
// using that TransportConfiguration
ConnectionFactory cfactory = (ConnectionFactory) HornetQJMSClient
.createConnectionFactoryWithoutHA(JMSFactoryType.CF,
transportConfiguration);
System.out.println("cfactory");
Connection connection;
try {
// Step 4.Create a JMS Connection
System.out.println("createConnection>");
connection = cfactory.createConnection();
System.out.println("createConnection");
// Step 5. Create a JMS Session
Session session = connection.createSession(false,
Session.AUTO_ACKNOWLEDGE);
System.out.println("createSession");
// Step 6. Create a JMS Message Producer
MessageProducer producer = session.createProducer(queue);
MessageConsumer consumer = session.createConsumer(queue);
//consumer.setMessageListener(this);
connection.start();
// Create a Text Message
TextMessage message = session
.createTextMessage("This is a text message hello");
System.out.println("Sent message: " + message.getText()
+ " JMStype: " + message.getJMSType());
// Step 8. Send the Message
producer.send(message);
//session.close();
//session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
ERROR: Unable to validate user: null
When change the line connection = cfactory.createConnection(); to this one connection = cfactory.createConnection("guest", "pass");
ERROR: Unable to validate user: guest.
VARIANT 2:
public void sendMessagetoJMS() {
Hashtable<String, String> ht = new Hashtable<String, String>();
ht.put(Context.INITIAL_CONTEXT_FACTORY,
"org.jnp.interfaces.NamingContextFactory");
ht.put(Context.PROVIDER_URL, "127.0.0.1");
// ht.put(Context.PROVIDER_URL, "jnp://localhost:1099");
ht.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
try {
lContext = new InitialContext(ht);
Hconnection = (ConnectionFactory) lContext
.lookup("ConnectionFactory");
q = (Queue) lContext.lookup("queue/test");
Hconn = (Connection) Hconnection.createConnection("guest", "guest");
session = Hconn.createSession(false, Session.AUTO_ACKNOWLEDGE);
messageProducer = session.createProducer(q);
/*
* Insert into Database
*/
Hconn.start();
TextMessage message = session
.createTextMessage("This is a text message hello");
message.setJMSType("hello"); // the first message from Client
System.out.println("Sent message: " + message.getText()
+ " JMStype: " + message.getJMSType());
// Step 8. Send the Message
messageProducer.send(message);
System.out.println("Message sent ");
Hconn.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
ERROR: Cannot instantiate class: org.jnp.interfaces.NamingContextFactory
When I chage the line ht.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory"); to this one : ht.put(Context.INITIAL_CONTEXT_FACTORY, "org.jboss.naming.remote.client.InitialContextFactory");
ERROR :
Feb 25, 2014 6:23:31 PM org.xnio.Xnio <clinit>
INFO: XNIO Version 3.0.3.GA
Feb 25, 2014 6:23:31 PM org.xnio.nio.NioXnio <clinit>
INFO: XNIO NIO Implementation Version 3.0.3.GA
Feb 25, 2014 6:23:32 PM org.jboss.remoting3.EndpointImpl <clinit>
INFO: JBoss Remoting version 3.2.3.GA
javax.naming.NamingException: Failed to create remoting connection
Caused by: org.jboss.remoting3.UnknownURISchemeException: No connection provider for URI scheme "null" is installed
I hope it post belongs to the same Forum.
Thanks in advance.
Alex