-
Dec 24th, 2011, 04:48 AM
#11
[a-z]+.txt is a regular expression and not a pattern. *.txt on other hand is a pattern.
Now as i said earlier, in order to use [a-z]+.txt, you need to use the filename-regex attribute and not filename-pattern.
If you use filename-pattern, one of the the valid values would be *.txt.
-
Dec 26th, 2011, 09:50 AM
#12
Thanks Amol - works fine with "*.txt"
Requirement was channel inbound adapter should read text file -> convert content into string -> send to jms outbound adapter (activemq)
Listener on a different machine should be able to receive this message - listener works fine if I use jms:listener container as shown below
<?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
="http://www.springframework.org/schema/p"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schem...ring-beans.xsd
http://www.springframework.org/schema/jms
http://www.springframework.org/schema/jms/spring-jms.xsd">
<bean id="connectionFactory"
class="org.apache.activemq.ActiveMQConnectionFacto ry"
p:brokerURL="tcp://localhost:61616" />
<bean id="simpleMessageListener"
class="SimpleMessageListener"/>
<jms:listener-container
container-type="default"
connection-factory="connectionFactory"
acknowledge="auto">
<jms:listener destination="queue.request"
ref="simpleMessageListener" method="onMessage"/>
</jms:listener-container>
</beans>
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.TextMessage;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlAp plicationContext;
public class SimpleMessageListener implements MessageListener {
public void onMessage(Message message)
{
TextMessage msg= (TextMessage)message;
System.out.println("received message is *********" + msg.toString());
}
public static void main(String[] args) throws Exception {
SimpleMessageListener test = new SimpleMessageListener();
test.process();
}
private void process()throws Exception
{
ApplicationContext context = new ClassPathXmlApplicationContext(
"dd/jmscommon.xml", SimpleMessageListener.class);
//FileCopyDemoCommon.displayDirectories(context);
Thread.sleep(5000);
}
}
-------------------------------------------------------------
But does not work if I use jndi context lookup like below - why is it so?? Actual requirement have remote listener as weblogic - mdb via foreign jms.
package com.hcl.util.jms.impl.activemq;
import java.util.Map;
import java.util.Properties;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.QueueConnection;
import javax.jms.QueueConnectionFactory;
import javax.jms.QueueSession;
import javax.naming.Context;
import javax.naming.NamingException;
import com.hcl.util.jms.JMSQueueRecieveUtil;
public class JMSActiveMQQueueRecieve implements JMSQueueRecieveUtil{
private Map properties;
private QueueConnectionFactory factory;
private boolean isConcurrent;
private String selectorExpression;
private MessageListener messageListener;
public JMSActiveMQQueueRecieve(Map properties){
this.properties=properties;
try {
javax.naming.Context ctx = new javax.naming.InitialContext(getInitialContextPrope rties());
factory = (javax.jms.QueueConnectionFactory)ctx.lookup((Stri ng)properties.get("QUEUE_CONNECTION_FACTORY_JNDI_N AME"));
isConcurrent=new Boolean((String)properties.get("CONCURRET_USERS")) ;
} catch (NamingException e) {
e.printStackTrace();
}
}
public Map getProperties() {
return properties;
}
public void reciveMessage(){
if(isConcurrent){
synchronized (this) {
recieveMessageFromActiveMQ();
}
}else{
recieveMessageFromActiveMQ();
}
}
public void recieveMessageFromActiveMQ(){
QueueConnection conn =null;
javax.jms.QueueSession session =null;
javax.jms.Queue myqueue = null;
MessageConsumer consumer =null;
try{
conn = factory.createQueueConnection();
conn.start();
session = conn.createQueueSession(false,QueueSession.AUTO_AC KNOWLEDGE);
myqueue = session.createQueue((String)properties.get("QUEUE_ NAME"));
//consumer =session.createConsumer(myqueue,selectorExpression );
consumer =session.createConsumer(myqueue);
consumer.setMessageListener(messageListener);
}catch(JMSException jmsException){
jmsException.printStackTrace();
}finally{
}
}
public String getSelectorExpression() {
return selectorExpression;
}
public void setSelectorExpression(String selectorExpression) {
this.selectorExpression = selectorExpression;
}
public MessageListener getMessageListener() {
return messageListener;
}
public void setMessageListener(MessageListener messageListener) {
this.messageListener = messageListener;
}
public void setProperties(Map properties) {
this.properties = properties;
}
private Properties getInitialContextProperties(){
Properties props = new Properties();
props.setProperty(Context.INITIAL_CONTEXT_FACTORY, (String)properties.get("INITIAL_CONTEXT_FACTORY")) ;
props.setProperty(Context.PROVIDER_URL,(String)pro perties.get("PROVIDER_URL"));
return props;
}
}
-
Dec 26th, 2011, 10:51 AM
#13
Please edit and format your post properly. It becomes difficult to read.
If you want to see how your post loos like, click "Go advanced" and wrap relevant portions of your code with the right quotes, preview before posting.
Whats not working as expected? Anything in the logs?
-
Dec 26th, 2011, 10:14 PM
#14
Amol - sending attachment file - jms.txt
Good framework like lightweight esb - keep it up!! -myself still need to understand various things.jms.txt
Requirement was channel inbound adapter should read text file -> convert content into string -> send to jms outbound adapter (activemq) --> Listener on remote machine should be able to subscribe messages
Remote Listener on a different/remote machine should be able to receive this message - listener works fine if I use jms:listener container as shown in attached code, no logs as such, I suspect jms properties(code1) using template and jndi(code2) do not match?
-
Dec 27th, 2011, 11:10 PM
#15
amol - sorry my mistake - things are working - myself was giving wrong queue name at remote listener side.
Quick question file polling adaper - file:inbound-channel-adapter with poller -> poller works only if filename is changed or new file is created in the directory but if an existing file once picked up by file:inbound-channel-adapter with poller is not again selected why is it so? Even if existing file is changed, it does not pickup - needs a new filename.
-
Dec 28th, 2011, 12:20 AM
#16
There is an AcceptOnceFileListFilter which accepts the file only once which causes the file not to be picked up the second time. To the best of my knowledge there is no filter currently in place that checks for the file updations and hence file updations are ignored.
If at all you do have such requirement, you might have to possibly have to write your own filter. It could be like computing the MD5 hash of the files and comparing them with the last computed hash. Computations be quiet resource intensive if the files are big and lots of files are present
-
Dec 29th, 2011, 04:14 AM
#17
jms:outbound-channel-adapter works fine with activemq, is it possible for this to work with weblogic 10.3.3 instead of activemq? Myself tried creating jms foreign server / message bridge on weblogic but did not work. I believe this is required directly jms-outbound-channel-adpater and jms-inbound-channel-adapter can connect with weblogic jms provider.
Thanks
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules