-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathJMSSendLargeMessage.java
More file actions
78 lines (64 loc) · 2.53 KB
/
JMSSendLargeMessage.java
File metadata and controls
78 lines (64 loc) · 2.53 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package JMS.JMStest;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.InputStreamReader;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
import org.apache.activemq.ActiveMQConnectionFactory;
public class JMSSendLargeMessage {
public static void main(String[] args) throws Exception {
// TODO Auto-generated method stub
Connection conn = null;
try {
ActiveMQConnectionFactory connFact = new ActiveMQConnectionFactory("tcp://localhost:61616");
MessageConsumer consumer = null;
conn = connFact.createConnection("abc", "abc123");
conn.start();
Session session = conn.createSession(true, Session.SESSION_TRANSACTED);
Queue dest = (Queue) session.createQueue("JMS_TEST_QUEUE");
//Code to test large message..
//Also have set acceptor url as below :
// <acceptor name="artemis">tcp://0.0.0.0:61616?tcpSendBufferSize=1048576;tcpReceiveBufferSize=1048576;protocols=CORE,AMQP,STOMP,HORNETQ,MQTT,OPENWIRE;useEpoll=true;amqpCredits=1000;
//amqpLowCredits=300;minLargeMessageSize=10</acceptor>
String fileName = "/home/swshende/Documents/LargeMessage.txt";
File file = new File(fileName);
FileInputStream fis = new FileInputStream(file);
InputStreamReader isr = new InputStreamReader(fis);
BufferedReader br = new BufferedReader(isr);
StringBuffer strbuf = new StringBuffer("helo");
String msg = "hello";
String line;
while((line = br.readLine()) != null){
//process the line
// System.out.println(line);
strbuf.append(line);
}
br.close();
MessageProducer producer = session.createProducer(dest);
msg= strbuf.toString();
for(int i=0; i < 1;i++){
TextMessage msg1 = session.createTextMessage(msg+i);
// msg1.setJMSExpiration(1000);
// msg1.setJMSExpiration(1000);
// producer.setTimeToLive(10000);
producer.send(msg1);
System.out.println("\n message sent .. ");
}
session.commit();
}
catch (JMSException ex) {
// handle exception (details omitted)
System.out.println("\n **** Error encountered ");
ex.printStackTrace();
}
finally {
conn.close();
}
}
}