Hikari connection pool giving IFXHOST does not exist on target class com.informix.jdbcx.IfxDataSource for informix - datasource

I am using this property with informix version 4.10.6.20151104
spring.informix.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.informix.datasource.dataSourceClassName=com.informix.jdbcx.IfxDataSource
spring.informix.datasource.dataSourceProperties.serverName=CISCO-UCCE-EXP
spring.informix.datasource.dataSourceProperties.portNumber=1504
spring.informix.datasource.dbcp2.pool-prepared-statements=true
spring.informix.datasource.dataSourceProperties.IFXHOST = cisco_ucce_exp_uccx
Getting error this
java.lang.RuntimeException: Property IFXHOST does not exist on target class com.informix.jdbcx.IfxDataSource
at com.zaxxer.hikari.util.PropertyElf.setProperty(PropertyElf.java:155) ~[HikariCP-2.4.7.jar:na]
at com.zaxxer.hikari.util.PropertyElf.setTargetFromProperties(PropertyElf.java:67) ~[HikariCP-2.4.7.jar:na]
at com.zaxxer.hikari.pool.PoolBase.initializeDataSource(PoolBase.java:295) ~[HikariCP-2.4.7.jar:na]
at com.zaxxer.hikari.pool.PoolBase.<init>(PoolBase.java:91) ~[HikariCP-2.4.7.jar:na]
at com.zaxxer.hikari.pool.HikariPool.<init>(HikariPool.java:101) ~[HikariCP-2.4.7.jar:na]
at com.zaxxer.hikari.HikariDataSource.getConnection(HikariDataSource.java:94) ~[HikariCP-2.4.7.jar:na]
at org.springframework.jdbc.datasource.DataSourceUtils.doGetConnection(DataSourceUtils.java:111) ~[spring-jdbc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
at org.springframework.jdbc.datasource.DataSourceUtils.getConnection(DataSourceUtils.java:77) ~[spring-jdbc-4.3.3.RELEASE.jar:4.3.3.RELEASE]
I have also tried same configuration with referring the
https://docs.oracle.com/cd/E19575-01/821-0185/beanj/index.html
for IfxIFXHost also I got the same issue
kindly help.
P.S I am new to Hikari

Never used Hikari before, but a quick test shows the properties you should add to the datasource to get a connection:
With "IFXHOST" I get the exception:
D:\JJTMP>grep IFXHOST p.java
config.addDataSourceProperty("IFXHOST", "420ito");
config.addDataSourceProperty("IfxIFXHOST", "420ito");
D:\JJTMP>java p
[main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
[main] ERROR com.zaxxer.hikari.util.PropertyElf - Property IFXHOST does not exist on target class com.informix.jdbcx.IfxDataSource
Exception in thread "main" java.lang.NullPointerException
at p.main(p.java:64)
Using "IfxIFXHOST" works:
D:\JJTMP>grep IFXHOST p.java
//config.addDataSourceProperty("IFXHOST", "420ito");
config.addDataSourceProperty("IfxIFXHOST", "420ito");
D:\JJTMP>javac p.java
D:\JJTMP>java p
[main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Starting...
[main] INFO com.zaxxer.hikari.pool.PoolBase - HikariPool-1 - Driver does not support get/set network timeout for connections. (M
ethod not supported : IfxSqliConnect.getNetworkTimeout())
[main] INFO com.zaxxer.hikari.HikariDataSource - HikariPool-1 - Start completed.
The Connection Object is of Class: class com.zaxxer.hikari.pool.HikariProxyConnection
systables,informix ,1048580
syscolumns,informix ,1048581
sysindices,informix ,1048582
systabauth,informix ,1048583
syscolauth,informix ,1048584
D:\JJTMP>
And just in case, the code I was using:
// ----- p.java -----
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
public class p
{
private static DataSource datasource;
public static DataSource getDataSource()
{
if(datasource == null)
{
HikariConfig config = new HikariConfig();
config.setDataSourceClassName("com.informix.jdbcx.IfxDataSource");
config.addDataSourceProperty("serverName", "ids1210");
//config.addDataSourceProperty("IFXHOST", "420ito");
config.addDataSourceProperty("IfxIFXHOST", "420ito");
config.addDataSourceProperty("PortNumber", "9088");
config.addDataSourceProperty("databaseName", "sysmaster");
config.addDataSourceProperty("user", "informix");
config.addDataSourceProperty("password", "ximrofni");
config.setMaximumPoolSize(10);
config.setAutoCommit(false);
datasource = new HikariDataSource(config);
}
return datasource;
}
public static void main(String[] args)
{
Connection connection = null;
PreparedStatement pstmt = null;
ResultSet resultSet = null;
try
{
DataSource dataSource = p.getDataSource();
connection = dataSource.getConnection();
pstmt = connection.prepareStatement("SELECT FIRST 5 * FROM systables");
System.out.println("The Connection Object is of Class: " + connection.getClass());
resultSet = pstmt.executeQuery();
while (resultSet.next())
{
System.out.println(resultSet.getString(1) + "," + resultSet.getString(2) + "," + resultSet.getString(3));
}
}
catch (Exception e)
{
try
{
connection.rollback();
}
catch (SQLException e1)
{
e1.printStackTrace();
}
e.printStackTrace();
}
}
}
// ----- p.java -----

So this worked for me
spring.informix.datasource.type=com.zaxxer.hikari.HikariDataSource
spring.informix.datasource.minimumIdle=10
spring.informix.datasource.maximumPoolSize=30
spring.informix.datasource.idleTimeout=500
spring.informix.datasource.dataSourceClassName=com.informix.jdbcx.IfxDataSource
spring.informix.datasource.dataSourceProperties.databaseName=db_
spring.informix.datasource.dataSourceProperties.serverName=CISCO-UCCE-EXP
#spring.informix.datasource.dataSourceProperties.url = jdbc:informix-sqli://CISCO-UCCE-EXP:1504/db_cra:INFORMIXSERVER=cisco_ucce_exp_uccx; Protocol=onsoctcp; client_locale=en_US.57372; db_locale=en_US.57372
spring.informix.datasource.dataSourceProperties.portNumber=1504
spring.informix.datasource.dbcp2.pool-prepared-statements=true
spring.informix.datasource.dataSourceProperties.LoginTimeout=0
spring.informix.datasource.connectionTimeout=0
spring.informix.datasource.dataSourceProperties.IfxIFXHOST=cisco_ucce_exp_uccx

Related

Multiple consumer issue in ActiveMQ with Wildfly

I am trying to build a basic registration form that sends the form data to a stateless bean through a Servlet. But inside ActiveMQ console I see two consumers for same queue also I need to register twice to add a new user in the list.
Any help is appreciated.
Logs:
WARNING: All illegal access operations will be denied in a future release
15:35:34,892 WARN [org.wildfly.extension.undertow] (MSC service thread 1-3) WFLYUT0101: Duplicate servlet mapping /Register found
15:35:35,008 INFO [javax.enterprise.resource.webcontainer.jsf.config] (ServerService Thread Pool -- 84) Initializing Mojarra 2.3.14.SP01 for context '/demowarproject'
15:35:35,436 INFO [org.wildfly.extension.undertow] (ServerService Thread Pool -- 84) WFLYUT0021: Registered web context: '/demowarproject' for server 'default-server'
15:35:35,509 INFO [org.jboss.as.server] (ServerService Thread Pool -- 46) WFLYSRV0010: Deployed "activemq-rar-5.17.2.rar" (runtime-name : "activemq-rar-5.17.2.rar")
15:35:35,510 INFO [org.jboss.as.server] (ServerService Thread Pool -- 46) WFLYSRV0010: Deployed "demowarproject.war" (runtime-name : "demowarproject.war")
15:35:35,510 INFO [org.jboss.as.server] (ServerService Thread Pool -- 46) WFLYSRV0010: Deployed "demoejbprojectEAR.ear" (runtime-name : "demoejbprojectEAR.ear")
15:35:35,551 INFO [org.jboss.as.server] (Controller Boot Thread) WFLYSRV0212: Resuming server
15:35:35,555 INFO [org.apache.activemq.ra.ActiveMQEndpointWorker] (Controller Boot Thread) Starting
15:35:35,561 INFO [org.apache.activemq.ra.ActiveMQEndpointWorker] (Controller Boot Thread) Starting
15:35:35,559 INFO [org.apache.activemq.ra.ActiveMQEndpointWorker] (default-threads - 1) Establishing connection to broker [tcp://localhost:61616]
15:35:35,565 INFO [org.apache.activemq.ra.ActiveMQEndpointWorker] (default-threads - 2) Establishing connection to broker [tcp://localhost:61616]
15:35:35,567 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0025: WildFly Full 21.0.2.Final (WildFly Core 13.0.3.Final) started in 8578ms - Started 648 of 874 services (390 services are lazy, passive or on-demand)
15:35:35,574 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0060: Http management interface listening on http://127.0.0.1:9990/management
15:35:35,574 INFO [org.jboss.as] (Controller Boot Thread) WFLYSRV0051: Admin console listening on http://127.0.0.1:9990
15:35:35,801 INFO [org.apache.activemq.ra.ActiveMQEndpointWorker] (default-threads - 2) Successfully established connection to broker [tcp://localhost:61616]
15:35:35,801 INFO [org.apache.activemq.ra.ActiveMQEndpointWorker] (default-threads - 1) Successfully established connection to broker [tcp://localhost:61616]
15:35:50,821 INFO [stdout] (default task-1) message sent!
15:35:51,154 INFO [stdout] (default-threads - 3) Registered!!, User count is: 1
15:35:51,158 INFO [stdout] (default-threads - 3) All users are:
15:35:51,158 INFO [stdout] (default-threads - 3) 87KumarPrashant#gmail.com
15:35:51,158 INFO [stdout] (default-threads - 3)
15:36:10,979 INFO [stdout] (default task-1) message sent!
15:36:10,995 INFO [stdout] (default-threads - 4) Registered!!, User count is: 1
15:36:10,996 INFO [stdout] (default-threads - 4) All users are:
15:36:10,996 INFO [stdout] (default-threads - 4) 87KumarPrashant#gmail.com
15:36:10,996 INFO [stdout] (default-threads - 4)
15:36:12,270 INFO [stdout] (default task-1) message sent!
15:36:12,286 INFO [stdout] (default-threads - 5) Email already registered 1
15:36:12,287 INFO [stdout] (default-threads - 5) All users are:
15:36:12,287 INFO [stdout] (default-threads - 5) 87KumarPrashant#gmail.com
15:36:12,287 INFO [stdout] (default-threads - 5)
15:36:13,438 INFO [stdout] (default task-1) message sent!
15:36:13,448 INFO [stdout] (default-threads - 6) Email already registered 1
15:36:13,449 INFO [stdout] (default-threads - 6) All users are:
15:36:13,449 INFO [stdout] (default-threads - 6) 87KumarPrashant#gmail.com
15:36:13,449 INFO [stdout] (default-threads - 6)
As you can see it needs twice to register before it says already registered, but user count is not increased second time (weird). And WildFly console shows two consumers for the same queue (also weird) as I am not using the same queue anywhere else.
ActiveMQ Console showing 2 consumers instead of 1:
Here are related files:
MDB:
import java.util.ArrayList;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Message;
import javax.jms.MessageListener;
import javax.jms.ObjectMessage;
#MessageDriven(activationConfig = {
#ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
#ActivationConfigProperty(propertyName = "destination", propertyValue = "jms/queue/demo")})
public class DemoEjb implements MessageListener
{
static ArrayList<User> usersList = new ArrayList<User>();
static int userCount = 0;
User u = null;
public void onMessage(Message message)
{
try
{
if (message instanceof ObjectMessage)
{
User user = (User) ((ObjectMessage) message).getObject();
if(user.getOperation().equals("register"))
registerUser(user);
// else
// loginUser(user);
}
} catch (Exception e)
{
e.printStackTrace();
}
}
public void registerUser(User user)
{
if (isUserPresent(user.getEmail())) {
System.out.println("Email already registered " + userCount);
giveAllUsers();
return;
}
addUser(user);
System.out.println("Registered!!, User count is: " + userCount);
giveAllUsers();
}
public boolean isUserPresent(String email)
{
return usersList.stream().anyMatch(d -> d.getEmail().equals(email));
}
public void addUser(User newUser)
{
usersList.add(newUser);
userCount++;
}
public void giveAllUsers()
{
System.out.println("All users are: ");
for(User u: usersList)
{
System.out.println(u.getEmail());
}
System.out.println();
}
}
User (POJO):
import java.io.Serializable;
public class User implements Serializable
{
private static final long serialVersionUID = 1L;
private String name;
private String password;
private String email;
private String operation;
public User(String name, String email, String password, String operation)
{
this.name = name;
this.email = email;
this.password = password;
this.operation = operation;
}
public String getName()
{
return this.name;
}
public void setOperation(String operation) {
this.operation = operation;
}
public String getPassword()
{
return this.password;
}
public String getEmail()
{
return this.email;
}
public void setName(String name)
{
this.name = name;
}
public void setPassword(String pass)
{
this.password = pass;
}
public String getOperation() {
return this.operation;
}
}
Servlet:
import java.io.IOException;
import java.io.PrintWriter;
import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Session;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.activemq.ActiveMQConnectionFactory;
import com.enovate.demoejb.User;
#WebServlet("/Register")
public class Register extends HttpServlet
{
private static final long serialVersionUID = 1L;
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String name = request.getParameter("userName");
String pass = request.getParameter("userPassword");
String email = request.getParameter("userEmail");
User user = new User(name, email, pass, "register");
try
{
System.out.println("message sent!");
sendMessage(user);
PrintWriter out = response.getWriter();
out.println("Message sent!");
} catch (Exception e)
{
e.printStackTrace();
}
}
public void sendMessage(User user) throws Exception
{
Connection connection = null;
try
{
ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("tcp://localhost:61616");
connection = connectionFactory.createConnection();
connection.start();
String queue = "jms/queue/demo";
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
Destination destinationQueue = session.createQueue(queue);
MessageProducer publisher = session.createProducer(destinationQueue);
ObjectMessage objectMessage = session.createObjectMessage();
objectMessage.setObject(user);
publisher.send(objectMessage);
session.close();
}
finally
{
closeConnection(connection);
}
}
private void closeConnection(Connection con)
{
try
{
if (con != null)
con.close();
}
catch(JMSException jmse)
{
System.out.println("Could not close connection " + con +" exception was " + jmse);
}
}
}
HTML file:
<html>
<head>
<meta charset="ISO-8859-1">
<title>Register</title>
</head>
<body>
<form method="post" action="Register">
Name: <input name="userName" type="text"><br>
Email: <input name="userEmail" type="email"><br>
Password: <input name="userPassword" type="password"><br>
<input type="submit" value="Register">
</form>
</body>
</html>
Web.xml:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_4_0.xsd" id="WebApp_ID" version="4.0">
<display-name>demowarproject</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.jsp</welcome-file>
<welcome-file>default.htm</welcome-file>
</welcome-file-list>
<servlet>
<description></description>
<display-name>Register</display-name>
<servlet-name>Register</servlet-name>
<servlet-class>com.enovate.demoservlet.Register</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>Register</servlet-name>
<url-pattern>/Register</url-pattern>
</servlet-mapping>
</web-app>
I was expecting it should work fine and have only one consumer.
It feels like there are two consumer created (don't know how) and then each try accepts the data one after the other.

Unable to cleanup Infinispan DefaultCacheManager in state FAILED

I am getting this Exception when trying to restart CacheManager, that failed to start.
Caused by: org.infinispan.jmx.JmxDomainConflictException: ISPN000034: There's already a JMX MBean instance type=CacheManager,name="DefaultCacheManager" already registered under 'org.infinispan' JMX domain. If you want to allow multiple instances configured with same JMX domain enable 'allowDuplicateDomains' attribute in 'globalJmxStatistics' config element
at org.infinispan.jmx.JmxUtil.buildJmxDomain(JmxUtil.java:53)
I think it's a bug, but am I correct?
The version used is 9.0.0.Final.
EDIT
The error can be seen using this code snippet.
import org.infinispan.configuration.cache.*;
import org.infinispan.configuration.global.*;
import org.infinispan.manager.*;
class Main {
public static void main(String[] args) {
System.out.println("Starting");
GlobalConfigurationBuilder global = GlobalConfigurationBuilder.defaultClusteredBuilder();
global.transport()
.clusterName("discover-service-poc")
.initialClusterSize(3);
ConfigurationBuilder builder = new ConfigurationBuilder();
builder.clustering().cacheMode(CacheMode.REPL_SYNC);
DefaultCacheManager cacheManager = new DefaultCacheManager(global.build(), builder.build(), false);
try {
System.out.println("Starting cacheManger first time.");
cacheManager.start();
} catch (Exception e) {
e.printStackTrace();
cacheManager.stop();
}
try {
System.out.println("Starting cacheManger second time.");
System.out.println("startAllowed: " + cacheManager.getStatus().startAllowed());
cacheManager.start();
System.out.println("Nothing happening because in failed state");
System.out.println("startAllowed: " + cacheManager.getStatus().startAllowed());
} catch (Exception e) {
e.printStackTrace();
cacheManager.stop();
}
cacheManager = new DefaultCacheManager(global.build(), builder.build(), false);
cacheManager.start();
}
}

Read data from database using UDF in pig

I have requirement to read data from a database and analyse the data using pig.
I have written a UDF in java Referring following link
register /tmp/UDFJars/CassandraUDF_1-0.0.1-SNAPSHOT-jar-with-dependencies.jar;
A = Load '/user/sampleFile.txt' using udf.DBLoader('10.xx.xxx.4','username','password','select * from customer limit 10') as (f1 : chararray);
DUMP A;
package udf;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.mapreduce.InputFormat;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.RecordReader;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.input.TextInputFormat;
import org.apache.pig.LoadFunc;
import org.apache.pig.backend.hadoop.executionengine.mapReduceLayer.PigSplit;
import org.apache.pig.data.Tuple;
import org.apache.pig.data.TupleFactory;
import com.data.ConnectionCassandra;
import com.datastax.driver.core.ResultSet;
import com.datastax.driver.core.Row;
import com.datastax.driver.core.Session;
public class DBLoader extends LoadFunc {
private final Log log = LogFactory.getLog(getClass());
Session session;
private ArrayList mProtoTuple = null;
private String jdbcURL;
private String user;
private String pass;
private int count = 0;
private String query;
ResultSet result;
List<Row> rows;
int colSize;
protected TupleFactory mTupleFactory = TupleFactory.getInstance();
public DBLoader() {
}
public DBLoader(String jdbcURL, String user, String pass, String query) {
this.jdbcURL = jdbcURL;
this.user = user;
this.pass = pass;
this.query = query;
}
#Override
public InputFormat getInputFormat() throws IOException {
log.info("Inside InputFormat");
// TODO Auto-generated method stub
try {
return new TextInputFormat();
} catch (Exception exception) {
log.error(exception.getMessage());
log.error(exception.fillInStackTrace());
throw new IOException();
}
}
#Override
public Tuple getNext() throws IOException {
log.info("Inside get Next");
Row row = rows.get(count);
if (row != null) {
mProtoTuple = new ArrayList<Object>();
for (int colNum = 0; colNum < colSize; colNum++) {
mProtoTuple.add(row.getObject(colNum));
}
} else {
return null;
}
Tuple t = mTupleFactory.newTuple(mProtoTuple);
mProtoTuple.clear();
return t;
}
#Override
public void prepareToRead(RecordReader arg0, PigSplit arg1) throws IOException {
log.info("Inside Prepare to Read");
session = null;
if (query == null) {
throw new IOException("SQL Insert command not specified");
}
if (user == null || pass == null) {
log.info("Creating Session with user name and password as: " + user + " : " + pass);
session = ConnectionCassandra.connectToCassandra1(jdbcURL, user, pass);
log.info("Session Created");
} else {
session = ConnectionCassandra.connectToCassandra1(jdbcURL, user, pass);
}
log.info("Executing Query " + query);
result = session.execute(query);
log.info("Query Executed :" + query);
rows = result.all();
count = 0;
colSize = result.getColumnDefinitions().asList().size();
}
#Override
public void setLocation(String location, Job job) throws IOException {
log.info("Inside Set Location");
try {
FileInputFormat.setInputPaths(job, location);
} catch (Exception exception) {
log.info("Some thing went wrong : " + exception.getMessage());
log.debug(exception);
}
}
}
Above is my pig script and java code.
Here /user/sampleFile.txt is a dummy file with no data.
I am getting following exception:
Pig Stack Trace
ERROR 1066: Unable to open iterator for alias A
org.apache.pig.impl.logicalLayer.FrontendException: ERROR 1066: Unable to open iterator for alias A
at org.apache.pig.PigServer.openIterator(PigServer.java:892)
at org.apache.pig.tools.grunt.GruntParser.processDump(GruntParser.java:774)
at org.apache.pig.tools.pigscript.parser.PigScriptParser.parse(PigScriptParser.java:372)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:198)
at org.apache.pig.tools.grunt.GruntParser.parseStopOnError(GruntParser.java:173)
at org.apache.pig.tools.grunt.Grunt.exec(Grunt.java:84)
at org.apache.pig.Main.run(Main.java:484)
at org.apache.pig.Main.main(Main.java:158)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:606)
at org.apache.hadoop.util.RunJar.run(RunJar.java:221)
at org.apache.hadoop.util.RunJar.main(RunJar.java:136)
Caused by: java.io.IOException: Job terminated with anomalous status FAILED
at org.apache.pig.PigServer.openIterator(PigServer.java:884)
... 13 more
Vivek! Do you even get in prepareToRead? (I see you did some logging, so it would be nice to know what you actually have in log) Also it would be really great to provide full stacktrace as I see you don't have full underlying exception.
Just some thoughts - I never tried writing a LoadFunc without implementing my own InputFormat and RecordReader - TextInputFormat checks for file existence and it's size (and creates a number of InputSplits based on file size(s)), so if your dummy file is empty there is a big possibility that no InputSplits are produced or zero-length InputSplit is produced. As it has zero-length it may cause pig to throw that exception. So the good suggestion is to implement own InputFormat (it's actually pretty easy). Also just as a fast try - try
set pig.splitCombination false
Probably it won't help, but it's easy to try.

Message Driven Bean onMessage() is not invoked in Glassfish

I am new to JMS coding. I am trying to create message from stand-alone java client which creates and send the message to queue and message driven bean is used for further processing of the messages.
I referred the following guidelines :
http://techtipsjava.blogspot.de/2013/05/jms-on-glassfish-queue-and-topic-with.html
I am using Glassfish application server (3.1). And setup everything to create JMS message from stand-alone java client.
Here is my code:
Client
import java.util.Properties;
import javax.jms.Connection;
import javax.jms.DeliveryMode;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
public class TruckMonitor {
public static void main(String args[]) {
try {
// Provide the details of remote JMS Client
Properties props = new Properties();
props.put(Context.PROVIDER_URL, "mq://localhost:7676");
// Create the initial context for remote JMS server
InitialContext cntxt = new InitialContext(props);
System.out.println("Context Created");
// JNDI Lookup for QueueConnectionFactory in remote JMS Provider
QueueConnectionFactory qFactory = (QueueConnectionFactory)cntxt.lookup("OmazanQueueConnectionFactory");
// Create a Connection from QueueConnectionFactory
Connection connection = qFactory.createConnection();
System.out.println("Connection established with JMS Provide ");
connection.start();
// Initialise the communication session
Session session = connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
// Create the message
TextMessage message = session.createTextMessage();
message.setJMSDeliveryMode(DeliveryMode.PERSISTENT);
message.setText(getMessage());
// JNDI Lookup for the Queue in remote JMS Provider
Queue queue = (Queue)cntxt.lookup("OmazanQueue");
// Create the MessageProducer for this communication
// Session on the Queue we have
MessageProducer mp = session.createProducer(queue);
// Send the message to Queue
mp.send(message);
System.out.println("Message Sent: " + getMessage());
// Make sure all the resources are released
mp.close();
session.close();
cntxt.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
private static String getMessage() {
String msg = null;
StringBuffer sbExceptionEvent = new StringBuffer("<exceptionEvent>");
sbExceptionEvent.append("</exceptionEvent>");
msg = sbExceptionEvent.toString();
return msg;
}
}
Message Driven Bean:
import java.util.Properties;
import javax.ejb.ActivationConfigProperty;
import javax.ejb.MessageDriven;
import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageListener;
import javax.jms.Queue;
import javax.jms.QueueConnectionFactory;
import javax.jms.Session;
import javax.jms.TextMessage;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
/** * Message-Driven Bean implementation class for: OmazanMDBean*/
#MessageDriven(
activationConfig = {
#ActivationConfigProperty(propertyName = "destinationType", propertyValue = "javax.jms.Queue"),
#ActivationConfigProperty(propertyName = "destination", propertyValue = "OmazanQueue"),
#ActivationConfigProperty(propertyName = "acknowledgeMode", propertyValue = "Auto-acknowledge")
},
mappedName = "OmazanQueue")
public class OmazanMDBean implements MessageListener {
/**
* Default constructor.
* #throws NamingException
* #throws JMSException
*/
public OmazanMDBean() {
super();
}
/**
* #see MessageListener#onMessage(Message)
*/
public void onMessage(Message message) {
System.out.println("Inside omMessage");
try {
message.acknowledge();
} catch (Exception e) {
e.printStackTrace();
}
TextMessage txtMessage = (TextMessage) message;
try {
System.out.println(txtMessage.getText());
} catch (Exception e) {
e.printStackTrace();
}
}
}
The problem is: onMessage() is not getting invoked. Did I miss anything? Please help me.
I guess if you remove #ActivationConfigProperty(propertyName = "destination", propertyValue = "OmazanQueue") from you MessageDrivenBean it will work since you have already used mappedName = "OmazanQueue"

ActiveMQ and JMS : Basic steps for novice

Hi all please give some basic about ActiveMQ with JMS for novice. And configuration steps also.
We are going to create a console based application using multithreading. So create an java project for console application.
Now follow these steps..........
Add javax.jms.jar, activemq-all-5.3.0.jar, log4j-1.2.15.jar to your project library.
(You can download all of above jar files from http://www.jarfinder.com/ .
create a file naming jndi.properties and paste these following texts .. ( Deatils for jndi.properties just Google it)
# START SNIPPET: jndi
java.naming.factory.initial = org.apache.activemq.jndi.ActiveMQInitialContextFactory
# use the following property to configure the default connector
java.naming.provider.url = tcp://localhost:61616
# use the following property to specify the JNDI name the connection factory
# should appear as.
#connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry
connectionFactoryNames = connectionFactory, queueConnectionFactory, topicConnectionFactry
# register some queues in JNDI using the form
# queue.[jndiName] = [physicalName]
queue.MyQueue = example.MyQueue
# register some topics in JNDI using the form
# topic.[jndiName] = [physicalName]
topic.MyTopic = example.MyTopic
# END SNIPPET: jndi
Add JMSConsumer.java
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class JMSConsumer implements Runnable{
private static final Log LOG = LogFactory.getLog(JMSConsumer.class);
public void run() {
Context jndiContext = null;
ConnectionFactory connectionFactory = null;
Connection connection = null;
Session session = null;
MessageConsumer consumer = null;
Destination destination = null;
String sourceName = null;
final int numMsgs;
sourceName= "MyQueue";
numMsgs = 1;
LOG.info("Source name is " + sourceName);
/*
* Create a JNDI API InitialContext object
*/
try {
jndiContext = new InitialContext();
} catch (NamingException e) {
LOG.info("Could not create JNDI API context: " + e.toString());
System.exit(1);
}
/*
* Look up connection factory and destination.
*/
try {
connectionFactory = (ConnectionFactory)jndiContext.lookup("queueConnectionFactory");
destination = (Destination)jndiContext.lookup(sourceName);
} catch (NamingException e) {
LOG.info("JNDI API lookup failed: " + e);
System.exit(1);
}
try {
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
consumer = session.createConsumer(destination);
connection.start();
try {
Thread.sleep(2000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
MessageListener listener = new MyQueueMessageListener();
consumer.setMessageListener(listener );
//Let the thread run for some time so that the Consumer has suffcient time to consume the message
try {
Thread.sleep(5000);
} catch (InterruptedException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (JMSException e) {
LOG.info("Exception occurred: " + e);
} finally {
if (connection != null) {
try {
connection.close();
} catch (JMSException e) {
}
}
}
}
}
Add JMSProducer.java
import javax.jms.*;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
public class JMSProducer implements Runnable{
private static final Log LOG = LogFactory.getLog(JMSProducer.class);
public JMSProducer() {
}
//Run method implemented to run this as a thread.
public void run(){
Context jndiContext = null;
ConnectionFactory connectionFactory = null;
Connection connection = null;
Session session = null;
Destination destination = null;
MessageProducer producer = null;
String destinationName = null;
final int numMsgs;
destinationName = "MyQueue";
numMsgs = 5;
LOG.info("Destination name is " + destinationName);
/*
* Create a JNDI API InitialContext object
*/
try {
jndiContext = new InitialContext();
} catch (NamingException e) {
LOG.info("Could not create JNDI API context: " + e.toString());
System.exit(1);
}
/*
* Look up connection factory and destination.
*/
try {
connectionFactory = (ConnectionFactory)jndiContext.lookup("queueConnectionFactory");
destination = (Destination)jndiContext.lookup(destinationName);
} catch (NamingException e) {
LOG.info("JNDI API lookup failed: " + e);
System.exit(1);
}
/*
* Create connection. Create session from connection; false means
* session is not transacted.create producer, set the text message, set the co-relation id and send the message.
*/
try {
connection = connectionFactory.createConnection();
session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
producer = session.createProducer(destination);
TextMessage message = session.createTextMessage();
for (int i = 0; i
Add MyQueueMessageListener.java
import java.io.*;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import javax.jms.*;
public class MyQueueMessageListener implements MessageListener {
private static final Log LOG = LogFactory.getLog(MyQueueMessageListener.class);
/**
*
*/
public MyQueueMessageListener() {
// TODO Auto-generated constructor stub
}
/** (non-Javadoc)
* #see javax.jms.MessageListener#onMessage(javax.jms.Message)
* This is called on receving of a text message.
*/
public void onMessage(Message arg0) {
LOG.info("onMessage() called!");
if(arg0 instanceof TextMessage){
try {
//Print it out
System.out.println("Recieved message in listener: " + ((TextMessage)arg0).getText());
System.out.println("Co-Rel Id: " + ((TextMessage)arg0).getJMSCorrelationID());
try {
//Log it to a file
BufferedWriter outFile = new BufferedWriter(new FileWriter("MyQueueConsumer.txt"));
outFile.write("Recieved message in listener: " + ((TextMessage)arg0).getText());
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}else{
System.out.println("~~~~Listener : Error in message format~~~~");
}
}
}
Add SimpleApp.java
public class SimpleApp {
//Run the producer first, then the consumer
public static void main(String[] args) throws Exception {
runInNewthread(new JMSProducer());
runInNewthread(new JMSConsumer());
}
public static void runInNewthread(Runnable runnable) {
Thread brokerThread = new Thread(runnable);
brokerThread.setDaemon(false);
brokerThread.start();
}
}
Now run SimpleApp.java class.
All da best. Happy coding.
Here it is a simple junit test for ActiveMQ and Apache Camel. This two technologies works very good together.
If you want more details about the code, you can find a post in my blog:
http://ignaciosuay.com/unit-testing-active-mq/
public class ActiveMQTest extends CamelTestSupport {
#Override
protected CamelContext createCamelContext() throws Exception {
CamelContext camelContext = super.createCamelContext();
ConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://localhost?broker.persistent=false");
camelContext.addComponent("activemq", jmsComponentClientAcknowledge(connectionFactory));
return camelContext;
}
#Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
#Override
public void configure() throws Exception {
from("mina:tcp://localhost:6666?textline=true&sync=false")
.to("activemq:processHL7");
from("activemq:processHL7")
.to("mock:end");
}
};
}
#Test
public void testSendHL7Message() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:end");
String m = "MSH|^~\\&|hl7Integration|hl7Integration|||||ADT^A01|||2.5|\r" +
"EVN|A01|20130617154644\r" +
"PID|1|465 306 5961||407623|Wood^Patrick^^^MR||19700101|1|\r" +
"PV1|1||Location||||||||||||||||261938_6_201306171546|||||||||||||||||||||||||20130617134644|";
mock.expectedBodiesReceived(m);
template.sendBody("mina:tcp://localhost:6666?textline=true&sync=false", m);
mock.assertIsSatisfied();
}