I am new to storm i am using rabbitmq within my spout that recieves tuples from some queue and there is a client running one some other machine that inserts tuples to that queue I ran a simple rabbitmq example program that works fine but when i am using it within storm spout it gest blocked at
connection = factory.newConnection();
even though my rabbitmq server is also running and on the same machine when i run example code it runs successfully.
print statements print to the statement
System.out.println(" setting host to 192.168.8.218..... ");
below is my complete spout class.
package storm.starter.spout;
import backtype.storm.spout.SpoutOutputCollector;
import backtype.storm.task.TopologyContext;
import backtype.storm.topology.OutputFieldsDeclarer;
import backtype.storm.topology.base.BaseRichSpout;
import backtype.storm.tuple.Fields;
import backtype.storm.tuple.Values;
import backtype.storm.utils.Utils;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.QueueingConsumer;
import java.util.Map;
import java.util.Random;
import java.net.*;
import java.io.*;
import java.lang.Exception;
import java.io.IOException;
public class RabbitmqSpout extends BaseRichSpout {
SpoutOutputCollector _collector;
public final static String QUEUE_NAME = "record";
ConnectionFactory factory;
Connection connection;
Channel channel;
QueueingConsumer consumer;
#Override
public void open(Map conf, TopologyContext context, SpoutOutputCollector collector)
{
_collector = collector;
System.out.println(" [*] Intilization of spout..... ");
try
{
factory = new ConnectionFactory();
System.out.println(" creating connection factory..... ");
factory.setHost("192.168.8.96");
System.out.println(" setting host to 192.168.8.218..... ");
connection = factory.newConnection();
System.out.println(" creating new connection..... ");
channel = connection.createChannel();
System.out.println(" creating new channel..... ");
channel.queueDeclare(QUEUE_NAME, false, false, false, null);
System.out.println(" Declaring queue..... ");
System.out.println(" [*] Waiting for messages. ");
}
catch(Exception exception)
{
System.out.println("Exception occurred. "+exception.getMessage());
}
}
#Override
public void nextTuple()
{
System.out.println("In wait of tuples.... ");
try
{
consumer = new QueueingConsumer(channel);
System.out.println(" trying to consume..... ");
channel.basicConsume(QUEUE_NAME, true, consumer);
while (true)
{
System.out.println(" trying to deliver..... ");
QueueingConsumer.Delivery delivery = consumer.nextDelivery();
String message = new String(delivery.getBody());
System.out.println(" getting string..... ");
System.out.println(" [x] Received '" + message + "'");
System.out.print("emitting Rabbitmq Queue tuple");
_collector.emit(new Values(message));
System.out.print("emitted Rabbitmq Queue tuple");
}
}
catch(IOException io)
{
System.out.println("Exception occurred. ");
}
catch(Exception exception)
{
System.out.println("Exception occurred. ");
}
}
#Override
public void ack(Object id) {
}
#Override
public void fail(Object id)
{
}
#Override
public void declareOutputFields(OutputFieldsDeclarer declarer)
{
declarer.declare(new Fields("record"));
}
}
connection = factory.newConnection()
Is done in RabbitMQConsumer() method of RabbitMQConsumer class because data is taken out of the queue by RabbitMQ consumer and that in turn gives data to your RabbitMQ spout.
please refer:
[https://github.com/ppat/storm-rabbitmq/tree/master/src/main/java/io/latent/storm/rabbitmq][1]
Related
I installed Glassfish5 and started it using eclipse. I also logged to the Glassfish admin console and created two queues namely Queue01 and Queue02 under the JMS Resources\Destination Resources option. The code doesn't but when I run it, the last thing it performs is the print statement before the lookup command. Here is my code:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Properties;
import javax.jms.ConnectionFactory;
import javax.jms.JMSContext;
import javax.jms.JMSException;
import javax.jms.JMSProducer;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.Queue;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
public class Main implements MessageListener{
public static void main(String[] args) throws JMSException,NamingException, IOException{
if(args.length!=3) System.out.println("usage: username subscribe-to-queue publish-to-queue");
else {
String username = args[0];
System.out.println("username: " + username + " | subscribe-to-queue-name " + args[1] + " | publish-to-queue-name " + args[2]);
Context initialContext = Main.getInitialContext();
Main myMain = new Main();
System.out.println("Before Queue");
Queue queue01 = (Queue) initialContext.lookup(args[1]);
Queue queue02 = (Queue) initialContext.lookup(args[2]);
//java:comp/DefaultJMSConnectionFactory is the default conection at the JMS app server (no need to define it)
System.out.println("Before ConnectionFactory");
JMSContext jmsContext = ((ConnectionFactory) initialContext.lookup("java:comp/DefaultJMSConnectionFactory")).createContext();
//we use jms context to pickup jms consumer and assign it our own class (Main)
System.out.println("Before createConsumer");
jmsContext.createConsumer(queue01).setMessageListener(myMain);
System.out.println("Before jmsProducer");
JMSProducer jmsProducer = jmsContext.createProducer();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String msgToSend = null;
System.out.println("Before while");
while(true) {
System.out.println("Please enter msg:");
msgToSend = bufferedReader.readLine();
if(msgToSend.equalsIgnoreCase("exit")) {
jmsContext.close();
System.exit(0);
}else {
System.out.println("Before send");
jmsProducer.send(queue02, "["+username+": "+msgToSend+"]");
System.out.println("after send");
}
}
}
}
#Override
public void onMessage(Message message) {
try{System.out.println(message.getBody(String.class));}
catch (JMSException e) {e.printStackTrace();}
}
public static Context getInitialContext () throws JMSException,NamingException
{
Properties prop = new Properties();
prop.setProperty("java.naming.factory.initial", "org.jnp.interfaces.NamingContextFactory");
prop.setProperty("java.naming.factory.url.pkgs", "org.jnp.interfaces");
prop.setProperty("java.naming.provider.url", "jnp://localhost:3700");
Context context = new InitialContext(prop);
//Context context = new InitialContext();
return context;
}
}
Any hint one what is wrong with my code that leads to not being able to execute the lookup command? The problem is that I'm not seeing any error messages to give me a hint on what is wrong. I tried changing the provider url without a luck.
I'm working on MQTT protocol and I try to publish and subscribe with 2 distincts Java applications.
My first application is "Publish". I'm publish on a MQTT server a message.
My second application is "Subscribe". I'm subscribe to a topic and try to receive the message. But I never receive the message.
When I run the 2 applications, I begin with the "Subscribe" application and after I run the "Publish" application. When the "Publish" application begin, I lose my connection to the "Subscribe" application and I can't receive my message.
In the "Subscribe" application, my method messageArrived() is never called by client.setCallback(this). (See the code below).
Here is my 2 code application :
Publish Application :
Class PubClient :
package publishclient;
import java.util.Random;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttAsyncClient;
import org.eclipse.paho.client.mqttv3.persist.MemoryPersistence;
public class PubClient implements MqttCallback {
MqttClient client;
MqttConnectOptions connOpt;
Random rand = new Random();
int nbRandom = 0;
int valMax =151, valMin = 40;
public PubClient() throws MqttException {
String broker = "tcp://88.177.147.17:1883"; // Adress MQTT Server
String clientId = "0bdd-4445-82f3-928f8ddb1887"; // ClientID
String topic1f = "ApplicationRio/capteur"; // Topic
int QoSserveur = 2;
try {
String uuid = "ac8da3c6-0bdd-4445-82f3-928f8ddb3294";
MemoryPersistence persistence = new MemoryPersistence();
// Create 2 objects : client and connOpt
client = new MqttClient(broker, clientId, persistence);
connOpt = new MqttConnectOptions();
connOpt.setCleanSession(true);
client.setCallback(this);
// Connection to MQTT server
System.out.println("Connexion a : " + broker + " Publisher");
client.connect(connOpt);
//Create random number for my message
nbRandom = valMin + rand.nextInt(valMax-valMin);
System.out.println("nb aleatoire = " + nbRandom);
String messageAEnvoyer = uuid + "//" + nbRandom;
System.out.println("Message a envoyer : " + messageAEnvoyer);
MqttMessage message = new MqttMessage();
message.setPayload(messageAEnvoyer.getBytes());
message.setQos(QoSserveur);
client.publish(topic1f, message);
} catch(MqttException e) {
e.printStackTrace();
}
}
#Override
public void connectionLost(Throwable thrwbl) {System.out.println("Perdue connexion");}
#Override
public void messageArrived(String string, MqttMessage mm) throws Exception {
System.out.println("Message recu est : "+ new String(mm.getPayload()));}
#Override
public void deliveryComplete(IMqttDeliveryToken imdt) {
System.out.println("Message delivre au broker");
}
}
The main (Publish) :
package publishclient;
import org.eclipse.paho.client.mqttv3.MqttException;
public class PublishClient {
public static void main(String[] args) throws MqttException {
PubClient publieur = new PubClient();
}
The "subscribe" application :
Class SubClient :
package subscribeclient;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttConnectOptions;
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.IMqttDeliveryToken;
public class SubClient implements MqttCallback {
MqttClient clientsub;
MqttConnectOptions connOpt;
public SubClient() throws MqttException{
String broker = "tcp://88.177.147.17:1883"; // Adress MQTT Server
String clientId = "0bdd-4445-82f3-928f8ddb1887"; // ClientID
String topic1f = "ApplicationRio/capteur"; // Topic
int QoSserveur = 2;
try{
// Create 2 objects : client and connOpt
clientsub = new MqttClient(broker, clientId);
connOpt = new MqttConnectOptions();
connOpt.setCleanSession(false);
connOpt.setKeepAliveInterval(30);
clientsub.setCallback(this);
// Connection to MQTT Server
System.out.println("Connexion a : " + broker + " Subscriber");
clientsub.connect(connOpt);
clientsub.subscribe(topic1f,QoSserveur);
} catch(MqttException e){
e.printStackTrace();
}
}
#Override
public void connectionLost(Throwable thrwbl) {
System.out.println("Connexion perdue");
}
#Override
public void messageArrived(String string, MqttMessage message) throws Exception {
System.out.println("Le message recu est : " + new String(message.getPayload()));
}
#Override
public void deliveryComplete(IMqttDeliveryToken imdt) {
System.out.println("Message arrive");
}
}
The main (Subscribe) :
package subscribeclient;
import org.eclipse.paho.client.mqttv3.MqttException;
public class SubscribeClient {
public static void main(String[] args) throws MqttException {
SubClient subscriber = new SubClient();
}
}
My 2 applications need to run in the same time, and I don't need to disconnect because I run applications all the time.
So, have you got an idea of why my "Subscribe Client" disconnect when I run the "Publish Client" and why I can't receive my message on my "Subscribe Message" ?
I use org.eclipse.paho.client.mqttv3-1.0.2.jar for the library for MQTT.
Client IDs have to be unique between ALL clients. You have used the same client ID for the publisher and subscriber so the broker will kick the subscriber off when the publisher connects.
I have two topics and one broker URL. I need to publish to these two topics using one broker URL.
I did it with one broker URL and one topic. Then I tried to do with two topics and write two subscriber class for each topic but when I run two subscriber classes one will shows connection lost.
Suggest some good examples to do this.
MQTTPublisher.java
import java.io.BufferedReader;
import java.io.InputStreamReader;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttClientPersistence;
import org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttTopic;
public class MQTTPublisher {
static final String BROKER_URL = "tcp://localhost:1883";// public mosquitto
// server
static final String TOPIC = "iotm/ej";// Change according to your
// application
static final String TOPIC1 = "iotm/stream1";
public static void main(String args[]) {
try {
// Creating new default persistence for mqtt client
MqttClientPersistence persistence = new MqttDefaultFilePersistence(
"/tmp");
// mqtt client with specific url and client id
MqttClient client1 = new MqttClient(BROKER_URL, "Publisher-ID",
persistence);
client.connect();
MqttTopic myTopic = client1.getTopic(TOPIC);
MqttTopic myTopic1 = client1.getTopic(TOPIC1);
String msg = "AMMA!DEVI!dURGA";
System.out.println("Enter the message to publish,Type quit to exit\n");
BufferedReader br = new BufferedReader(new
InputStreamReader(System.in));
msg = br.readLine();
while (!msg.equals("quit")) {
myTopic.publish(new MqttMessage(msg.getBytes()));
System.out.println("Message published on" + TOPIC);
myTopic1.publish(new MqttMessage(msg.getBytes()));
System.out.println("Message published on" + TOPIC1);
msg = br.readLine();
}
myTopic.publish(new MqttMessage(msg.getBytes()));
myTopic1.publish(new MqttMessage(msg.getBytes()));
// client.disconnect();
} catch (MqttException e) {
e.printStackTrace();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
MQTTSubscriber.java
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence;
import org.eclipse.paho.client.mqttv3.MqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttTopic;
public class MQTTSubscriber {
static final String BROKER_URL = "tcp://localhost:1883";// public
// mosquitto server
static final String TOPIC = "iotm/ej"; // Change according to your
public static void main(String args[]) {
try {
// Creating new default persistence for mqtt client
MqttDefaultFilePersistence persistence = new MqttDefaultFilePersistence(
"/tmp");
// mqtt client with specific url and a random client id
MqttClient client1 = new MqttClient(BROKER_URL, "Subscriber-ID",
persistence);
client1.connect();
System.out.println("Subscribing to topic '" + TOPIC + "' from "
+ client1.getServerURI());
// Subscribing to specific topic
client1.subscribe(TOPIC);
// It will trigger when a new message is arrived
MqttCallback callback = new MqttCallback() {
#Override
public void messageArrived(MqttTopic arg0, MqttMessage arg1)
throws Exception {
System.out.println("Message:"
+ new String(arg1.getPayload()));
}
#Override
public void deliveryComplete(MqttDeliveryToken arg0) {
}
#Override
public void connectionLost(Throwable arg0) {
System.out.println("Connection lost");
}
};
// Continue waiting for messages until the Enter is pressed
client1.setCallback(callback);
/*
* System.out.println("Press <Enter> to exit"); try {
* System.in.read(); } catch (IOException e) { // If we can't read
* we'll just exit }
*/
// client.disconnect();
// System.out.println("Client Disconnected");
} catch (MqttException e) {
e.printStackTrace();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
MQTTSubscriber2.java
import org.eclipse.paho.client.mqttv3.MqttCallback;
import org.eclipse.paho.client.mqttv3.MqttClient;
import org.eclipse.paho.client.mqttv3.MqttDefaultFilePersistence;
import org.eclipse.paho.client.mqttv3.MqttDeliveryToken;
import org.eclipse.paho.client.mqttv3.MqttException;
import org.eclipse.paho.client.mqttv3.MqttMessage;
import org.eclipse.paho.client.mqttv3.MqttTopic;
public class MQTTSubscriber2 {
static final String BROKER_URL = "tcp://localhost:1883";// public
// mosquitto server
static final String TOPIC = "iotm/stream1";
public static void main(String args[]) {
try {
// Creating new default persistence for mqtt client
MqttDefaultFilePersistence persistence = new MqttDefaultFilePersistence(
"/tmp");
// mqtt client with specific url and a random client id
MqttClient client = new MqttClient(BROKER_URL, "Subscriber-ID",
persistence);
client.connect();
System.out.println("Subscribing to topic '" + TOPIC + "' from "
+ client.getServerURI());
// Subscribing to specific topic
client.subscribe(TOPIC);
// It will trigger when a new message is arrived
MqttCallback callback = new MqttCallback() {
#Override
public void messageArrived(MqttTopic arg0, MqttMessage arg1)
throws Exception {
System.out.println("Message:"
+ new String(arg1.getPayload()));
}
#Override
public void deliveryComplete(MqttDeliveryToken arg0) {
}
#Override
public void connectionLost(Throwable arg0) {
System.out.println("Connection lost");
}
};
// Continue waiting for messages until the Enter is pressed
client.setCallback(callback);
/*
* System.out.println("Press <Enter> to exit"); try {
* System.in.read(); } catch (IOException e) { // If we can't read
* we'll just exit }
*/
// client.disconnect();
// System.out.println("Client Disconnected");
} catch (MqttException e) {
e.printStackTrace();
} catch (Exception e) {
System.err.println(e.getMessage());
}
}
}
If you are running 2 separate instances of the subscriber code then they will both need different client ids. If you run 2 with the same then the first will be disconnected from the broker when the second connects.
My client stopped working when i use the method that have a class object "bd" below as a parameter although i use listener object successfully. "Marked as bold"
NOte that , when i tried to use another method that have for example any pramater "STring" works successfully.
import java.util.Properties;
import org.omg.CORBA.ORB;
import org.omg.PortableServer.POA;
import org.omg.PortableServer.POAHelper;
import org.omg.CosNaming.NameComponent;
import org.omg.CosNaming.NamingContext;
import org.omg.CosNaming.NamingContextHelper;
public class BackupDaemonMain {
public static void main(String[] args) {
try {
//initialize orb
Properties props = System.getProperties();
props.put("org.omg.CORBA.ORBInitialPort", "1050");
//Replace MyHost with the name of the host on which you are running the server
props.put("org.omg.CORBA.ORBInitialHost", "localhost");
ORB orb = ORB.init(args, props);
System.out.println("Initialized ORB");
//Instantiate Servant and create reference
POA rootPOA = POAHelper.narrow(
orb.resolve_initial_references("RootPOA"));
MessageListenerImpl listener = new MessageListenerImpl();
BackupDaemonImpl bdImpl=new BackupDaemonImpl();
// bdImpl.backupDaemonUser("Yarab");
rootPOA.activate_object(listener);
rootPOA.activate_object(bdImpl);
MessageListener ref = MessageListenerHelper.narrow(
rootPOA.servant_to_reference(listener));
**BackupDaemon bd = BackupDaemonHelper.narrow(
rootPOA.servant_to_reference(bdImpl));**
System.out.println("After rootPOA.servant_to_reference(bdImpl)); ");
//Resolve MessageServer
MessageServer msgServer = MessageServerHelper.narrow(
orb.string_to_object("corbaname:iiop:1.2#localhost:1050#MessageServer"));
BackupServer bdServer=BackupServerHelper.narrow(
orb.string_to_object("corbaname:iiop:1.2#localhost:1050#BackupServer"));
//Register listener reference (callback object) with MessageServer
/* if(bd==null)
{
System.out.println("Null");
}
else
{
System.out.println("Not Null With " + bd.backupDaemonUser());
}*/
// bd.backupDaemonMacAddress("YYYYYYYYYY");
System.out.println("Initialized ORB +++++++++++++++++++++++ ");
msgServer.register(ref);
**bdServer.registerBackupDaemon(bd);**
System.out.println("Initialized ORB +++++++++++++++++++++++ )))))))))");
//System.out.println("I am Here" +
//bd.deleteBackup("00000000000","asdas");//);
System.out.println("Initialized ORB +++++++++++++++++++++++ _____________________________");
System.out.println("Listener registered with MessageServer With User :- ");
System.out.println("Backup Daemon registered with BackupServer With User :- " );
//Activate rootpoa
rootPOA.the_POAManager().activate();
//Wait for messages
System.out.println("Wait for incoming messages");
orb.run();
} catch (Exception e) {
e.printStackTrace();
}
}
}
Server implementation is
// BackupServerImpl.java
import java.util.Enumeration;
import java.util.Vector;
import org.omg.CosNaming.*;
import org.omg.CosNaming.NamingContextPackage.*;
import org.omg.CORBA.*;
import org.omg.PortableServer.*;
import org.omg.PortableServer.POA;
import java.util.Properties;
// import util.CORBAAlgorithms;
public class BackupServerImpl extends BackupServerPOA {
private ORB orb;
public void setORB(ORB orb_val){
orb = orb_val;
}
public String sayHello(){
return "\nHello world !!\n";
}
public void shutdown(){
orb.shutdown(false);
}
// This BankServer's list of Banks.
private Vector myBackups;
public BackupServerImpl()
{
//super("In Impl");
System.out.println("\n \t # Constructor of Server");
}
public BackupServerImpl(String name) {
// super(name);
myBackups = new Vector();
}
public boolean registerBackupDaemon(BackupDaemon bd) throws InvalidBackupDaemonException
{
System.out.println("\n \t Backup Agent Registration With User" + bd.backupDaemonUser());
return true;
}
public boolean unRegisterBackupDaemon(String backupDaemonMacAddress) throws
InvalidBackupDaemonException {
System.out.println("Backup Daemon Un-Registration With Mac " + backupDaemonMacAddress);
return true;
}
public BackupDaemon[] getBackupDeamons() {
BackupDaemon[] list = new BackupDaemon[myBackups.size()];
myBackups.copyInto(list);
Enumeration e = myBackups.elements();
while (e.hasMoreElements()) {
((BackupDaemon)e.nextElement())._duplicate();
}
return list;
}
}
You may have missed the NameService in our urls
corbaname:iiop:1.2#localhost:1050/NameService#BackupServer
The call to bdServer could also hang on the remote site...
your run method of org.omg.CORBA.ORB blocks on the current thread. You should have started it in a separate thread. Refer the javadoc . Run your ORB like
Thread orbThread = new Thread("Orb Thread") {
public void run() {
orb.run();
}
};
orbThread.start();
I am using JSMPP from Google to receive SMS messages from SMS Service Centre. Sometimes, my program stops receiving SMS from SMSC, I have to close the program and Re-Open the program. Then Queued SMSes from SMSC starts receive. This happens after some time, like after 7 or 8 hours. Here is the code I'v used
SMPP Init Code
l.info("SMPP Initialization");
SMPPSession s = new SMPPSession();
s.setMessageReceiverListener(new Receive(s));
s.connectAndBind(Settings.smsc_host,Settings.smsc_port, BindType.BIND_TRX,
Settings.smsc_user, Settings.smsc_password,Settings.smsc_msg_setting, TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN, null, Settings.smsc_timeout);
ProcessSMS.s = s;
l.info("SMPP Initialization Success");
SMS Receive Code
package sms;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.log4j.Logger;
import org.jsmpp.bean.AlertNotification;
import org.jsmpp.bean.DataSm;
import org.jsmpp.bean.DeliverSm;
import org.jsmpp.bean.MessageType;
import org.jsmpp.extra.ProcessRequestException;
import org.jsmpp.session.DataSmResult;
import org.jsmpp.session.MessageReceiverListener;
import org.jsmpp.session.Session;
import processor.ProcessSMS;
public class Receive implements MessageReceiverListener {
private static final ExecutorService pool = Executors.newFixedThreadPool(10);
private static final Logger l = Logger.getLogger(Receive.class);
private Thread thread;
public Receive(){
super();
}
public Receive(Session s){
this();
}
#Override
public DataSmResult onAcceptDataSm(DataSm arg0, Session arg1)
throws ProcessRequestException {
return null;
}
#Override
public void onAcceptAlertNotification(AlertNotification arg0) {
}
#Override
public void onAcceptDeliverSm(DeliverSm arg0)
throws ProcessRequestException {
l.info("Received SMS " + arg0);
if(MessageType.SMSC_DEL_RECEIPT.containedIn(arg0.getEsmClass())){
}else{
pool.submit(new ProcessSMS(arg0));
//thread = new Thread(new ProcessSMS(arg0));
//thread.start();
}
}
}
And here is the state change class
package sms;
import java.io.IOException;
import global.Shared;
import log.SMSCStateLogger;
import org.jsmpp.bean.BindType;
import org.jsmpp.bean.NumberingPlanIndicator;
import org.jsmpp.bean.TypeOfNumber;
import org.jsmpp.extra.SessionState;
import org.jsmpp.session.SMPPSession;
import org.jsmpp.session.Session;
import org.jsmpp.session.SessionStateListener;
import processor.ProcessSMS;
import settings.Settings;
public class StateChange implements SessionStateListener{
private static SMSCStateLogger l = new SMSCStateLogger(StateChange.class);
private Session s;
#Override
public void onStateChange(SessionState arg0, SessionState arg1, Object arg2) {
//arg0 = new State
//arg1 = old State
if(!arg0.isBound() && arg1.isBound()){
int con = Shared.getNextReConnectInterval();
l.info("State changed from " + arg1 + " to " + arg0 + " on " + arg2);
while(true){
l.info("Re Connection in " + con + " ms");
try{
Thread.sleep(con);
}catch(InterruptedException iex){
l.fatal("Re Connection failed due to exception " + iex);
break;
}
s = new SMPPSession();
((SMPPSession) s).setMessageReceiverListener(new Receive(s));
s.addSessionStateListener(new StateChange());
try{
((SMPPSession) s).connectAndBind(Settings.smsc_host,Settings.smsc_port, BindType.BIND_TRX,
Settings.smsc_user, Settings.smsc_password,Settings.smsc_msg_setting, TypeOfNumber.UNKNOWN,
NumberingPlanIndicator.UNKNOWN, null, Settings.smsc_timeout);
}catch(IOException ioex){
l.fatal("Connection failed due to " + ioex.getMessage());
}
ProcessSMS.s = (SMPPSession) s;
l.info("Re Connection success");
break;
}
}
}
}
Does anybody have an idea what is going on ?
Updated the JSMPP API from https://github.com/uudashr/jsmpp.
Download the source with git
run mvn install to create the jar archive.