Hi Aliosha,

I tried the same example with above spring-config.xml and was able to run
the JMS Subscriber without issue.

However according to the error log it seems your spring configuration is
unable to find the InitialContextFactory of the JNDI Provider. Therefore
first make sure you have correctly added 'andes-client-0.13.wso2v8.jar'
file as a dependency into the project classpath.
If it is already there in the external libraries, please define
InitialContextFactory as <jee:environment> element in configuration as
below and see with running subscriber client back.

<jee:jndi-lookup id="connectionFactory" jndi-name="TopicConnectionFactory">
    <jee:environment>

java.naming.factory.initial=org.wso2.andes.jndi.PropertiesFileInitialContextFactory
    </jee:environment>
</jee:jndi-lookup>

Thanks,
Ishara


On Wed, Jan 1, 2014 at 4:22 PM, Aliosha <aliosh...@gmail.com> wrote:

> I m facing up with the subscriber client configuration using spring-jms. I
> m following this example:
>
> http://docs.wso2.org/display/MB210/Topic+subscriber+and+topic+publisher
>
> in which the client is coded like this:
>
> import javax.jms.JMSException;
> import javax.jms.Message;
> import javax.jms.QueueSession;
> import javax.jms.TextMessage;
> import javax.jms.Topic;
> import javax.jms.TopicConnection;
> import javax.jms.TopicConnectionFactory;
> import javax.jms.TopicSession;
> import javax.naming.Context;
> import javax.naming.InitialContext;
> import javax.naming.NamingException;
> import java.util.Properties;
>
> public class TopicSubscriber {
>     public static final String QPID_ICF = 
> "org.wso2.andes.jndi.PropertiesFileInitialContextFactory";
>     private static final String CF_NAME_PREFIX = "connectionfactory.";
>     private static final String CF_NAME = "qpidConnectionfactory";
>     String userName = "admin";
>     String password = "admin";
>     private static String CARBON_CLIENT_ID = "carbon";
>     private static String CARBON_VIRTUAL_HOST_NAME = "carbon";
>     private static String CARBON_DEFAULT_HOSTNAME = "localhost";
>     private static String CARBON_DEFAULT_PORT = "5672";
>     String topicName = "MYTopic";
>
>     public static void main(String[] args) throws NamingException, 
> JMSException {
>         TopicSubscriber topicSubscriber = new TopicSubscriber();
>         topicSubscriber.subscribe();
>     }
>     public void subscribe() throws NamingException, JMSException {
>         Properties properties = new Properties();
>         properties.put(Context.INITIAL_CONTEXT_FACTORY, QPID_ICF);
>         properties.put(CF_NAME_PREFIX + CF_NAME, 
> getTCPConnectionURL(userName, password));
>         System.out.println("getTCPConnectionURL(userName,password) = " +    
> getTCPConnectionURL(userName, password));
>         InitialContext ctx = new InitialContext(properties);
>     // Lookup connection factory
>         TopicConnectionFactory connFactory = (TopicConnectionFactory) 
> ctx.lookup(CF_NAME);
>         TopicConnection topicConnection = connFactory.createTopicConnection();
>         topicConnection.start();
>         TopicSession topicSession =
>             topicConnection.createTopicSession(false, 
> QueueSession.AUTO_ACKNOWLEDGE);
>     // Send message
>         Topic topic = topicSession.createTopic(topicName);
>         javax.jms.TopicSubscriber topicSubscriber = 
> topicSession.createSubscriber(topic);
>         Message message = topicSubscriber.receive();
>         if (message instanceof TextMessage) {
>             TextMessage textMessage = (TextMessage) message;
>             System.out.println("textMessage.getText() = " + 
> textMessage.getText());
>         }
>         topicSubscriber.close();
>         topicSession.close();
>         topicConnection.stop();
>         topicConnection.close();
>     }
>     public String getTCPConnectionURL(String username, String password) {
>         // 
> amqp://{username}:{password}@carbon/carbon?brokerlist='tcp://{hostname}:{port}'
>         return new StringBuffer()
>             .append("amqp://").append(username).append(":").append(password)
>             .append("@").append(CARBON_CLIENT_ID)
>             .append("/").append(CARBON_VIRTUAL_HOST_NAME)
>             
> .append("?brokerlist='tcp://").append(CARBON_DEFAULT_HOSTNAME).append(":").append(CARBON_DEFAULT_PORT).append("'")
>             .toString();
>     }
> }
>
>
> By Spring i'm trying to set up the connection factory by this code:
>
> <?xml version="1.0" encoding="UTF-8"?>
> <beans xmlns="http://www.springframework.org/schema/beans";
>    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
>   xmlns:jms="http://www.springframework.org/schema/jms";
>   xmlns:jee="http://www.springframework.org/schema/jee";
>    xsi:schemaLocation="http://www.springframework.org/schema/beans 
> http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
>    http://www.springframework.org/schema/jms 
> http://www.springframework.org/schema/jms/spring-jms-3.0.xsd
>    http://www.springframework.org/schema/jee 
> http://www.springframework.org/schema/jee/spring-jee.xsd";>
>
> <jee:jndi-lookup id="connectionFactory" jndi-name="TopicConnectionFactory"/>
>
>
> But in this way i get this error: javax.naming.NoInitialContextException: 
> Need to specify class name in environment or system property, or as an applet 
> parameter, or in an application resource file: java.naming.factory.initial
>
> Could anyone show me the correct spring-jms configuration?
>
> Best regards and my best wishes for the new year.
>
>
>


-- 
Ishara Premasada
Software Engineer,
WSO2 Inc. http://wso2.com/


*Blog   :  http://isharapremadasa.blogspot.com/
<http://isharapremadasa.blogspot.com/>Twitter       :
https://twitter.com/ishadil <https://twitter.com/ishadil>Mobile       : +94
714445832*
_______________________________________________
Dev mailing list
Dev@wso2.org
http://wso2.org/cgi-bin/mailman/listinfo/dev

Reply via email to