Controlling commit order for a Two-Phase Commit transaction - websphere

We have a java application running on Webshere Application Server 8.5.5. There are two processes running in separate JVMs.
The application is doing some integration using an IBM Webshere Queue Manager and an Oracle 11c database. Both JMS and JDBC resources are configured to use XA transactions.
PROCESS 1:
Read a message from a MESSAGES queue and extract a message key used to identify related messages
Saves message to the database.
Check if the message key does not exist in a KEYS table and if it doesn't it inserts it
ONLY if the insert above happens it puts a message key into a KEYS queue
Commit the transaction
PROCESS 2:
Gets the message key from the KEYS queue
Deletes the message key from the KEYS table
Process all messages associated with received message key from MESSAGES table
What we observed is that in about 5 percent of the cases after getting the message key from the KEYS queue the PROCESS 2 sometimes cannot find the record to delete from the KEYS table just to become available milliseconds later. Trying to delete it multiple times fixed the problem but it became clear that even if PROCESS 1 is XA enabled it commits the JMS resource first and then the JDBC bringing for a very short period of time the data in an inconsistent state.
So here is my question:
Is there a way to force transaction manager to commit JDBC first and then the JMS?
We find this on IBM knowledge center and we try to configure commit-priority like this:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar-ext xmlns="http://websphere.ibm.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-ext_1_0.xsd"
version="1.0">
<session name="RepositoryInstanceFacade">
<resource-ref name="jms/MQConnectionFactory" commit-priority="1" isolation-level="TRANSACTION_READ_COMMITTED"/>
<resource-ref name="jdbc/MessageManagerDB" commit-priority="2" isolation-level="TRANSACTION_READ_COMMITTED"/>
</session>
</ejb-jar-ext>
However this did not solve our problem. I am sure we are not the only ones facing this problem but I just ran out of idea about what to try more. We ended up by putting the message key back in the KEYS queue and that solved the problem but it looks to me like a very unorthodox work around rather than a good solution for a critical 24 x 7 application.
Thank you in advance for your inputs.
UPDATE
I added this resource bindings file ibm-ejb-jar-bnd.xml file in the META-INF folder of my ejb application but still no luck. As part of the deployment I could see IBM manipulated that file and transformed it into an XMI file
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar-bnd
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee
http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_0.xsd"
version="1.0">
<session name="RepositoryInstanceFacade">
<resource-ref name="jdbc/MessageManagerDB" binding-name="jdbc/MessageManagerDB"/>
</session>
</ejb-jar-bnd>
UPDATE 2
I ended up with below configuration in two JVMs each JVM running its own application:
application.xml:
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/application_6.xsd"
version="6">
...
<resource-ref>
<description>XA Message Manager Data Source</description>
<res-ref-name>java:app/env/jdbc/MessageManagerDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</application>
ibm-aplication-bnd.xml:
<?xml version="1.0" encoding="UTF-8"?>
<application-bnd
xmlns="http://websphere.ibm.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee
http://websphere.ibm.com/xml/ns/javaee/ibm-application-bnd_1_0.xsd"
version="1.0">
<resource-ref name="java:app/env/jdbc/MessageManagerDB" binding-name="jdbc/MessageManagerDB"/>
</application-bnd>
ibm-ejb-jar-ext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar-ext xmlns="http://websphere.ibm.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-ext_1_0.xsd"
version="1.0">
<session name="RepositoryInstanceFacade">
<resource-ref name="java:app/env/jdbc/MessageManagerDB" isolation-level="TRANSACTION_READ_COMMITTED" commit-priority="2"/>
</session>
</ejb-jar-ext>
spring data source bean:
<jee:jndi-lookup id="messageManagerDB" jndi-name="java:app/env/jdbc/MessageManagerDB"/>
And run again my tests. I was very happy during the test run as no warning messages came in the logs. However giving the test was running for a few hours it was hard to manually check all the time. In the end there were still three warning messages showing that JMS message was still read from the queue before the database insert was available. Am I still missing something?
Note that I took out any setting for JMS connection factory as according with the IBM documentation it would stay set to zero so it would have a lower commit priority than JDBC.
UPDATE 3
As advised by the comment and by IBM support I ended up with the following settings below:
ejb-jar.xml:
<session name="RepositoryInstanceFacade">
...
<resource-ref>
<description>XA Message Manager Data Source</description>
<res-ref-name>jdbc/MessageManagerDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</session>
ibm-ejb-jar-bnd.xml:
<resource-ref name="jdbc/MessageManagerDB" binding-name="jdbc/MessageManagerDB"/>
ibm-ejb-jar-ext.xml:
<session name="RepositoryInstanceFacade">
<resource-ref name="jdbc/MessageManagerDB" isolation-level="TRANSACTION_READ_COMMITTED" commit-priority="2"/>
</session>
spring data source bean:
<jee:jndi-lookup id="messageManagerDB" jndi-name="java:comp/env/jdbc/MessageManagerDB"/>
With these settings in place JMS is still committed first and the JDBC last so it is still not working as expected.

Per the question that I asked in the comments, the resource reference is not actually being used to look up the resource, which is why the commit-priority attribute isn't being honored. In the UPDATE section of the question, you've gotten closer by adding the resource reference binding for the JDBC resource (you'll also need an equivalent for the JMS resource). You will also need to define the resource references in an ejb-jar.xml deployment descriptor (or annotation equivalent if you prefer), and then to look up the resources from your application, you need to use the namespace for the resource reference, which by default is java:comp/env, so you will need to look up the resources as java:comp/env/jms/MQConnectionFactory and java:comp/env/jdbc/MessageManagerDB. If you need visibility outside of the component level, you could would need to define at another scope such as java:module/env or java:app/env which would mean updating the resource reference name to the corresponding value as well.
UPDATE: example of ejb deployment descriptor/bindings/extensions with java:app name
ejb-jar.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar xmlns="http://java.sun.com/xml/ns/javaee" version="3.0" metadata-complete="false">
<enterprise-beans>
<session>
<ejb-name>RepositoryInstanceFacade</ejb-name>
<resource-ref>
<description>XA Message Manager Data Source</description>
<res-ref-name>java:app/env/jdbc/MessageManagerDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
<res-sharing-scope>Shareable</res-sharing-scope>
</resource-ref>
</session>
</enterprise-beans>
</ejb-jar>
ibm-ejb-jar-bnd.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar-bnd xmlns="http://websphere.ibm.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-bnd_1_0.xsd"
version="1.0">
<session name="RepositoryInstanceFacade">
<resource-ref name="java:app/env/jdbc/MessageManagerDB" binding-name="jdbc/MessageManagerDB"/>
</session>
</ejb-jar-bnd>
ibm-ejb-jar-ext.xml:
<?xml version="1.0" encoding="UTF-8"?>
<ejb-jar-ext xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://websphere.ibm.com/xml/ns/javaee"
xsi:schemaLocation="http://websphere.ibm.com/xml/ns/javaee http://websphere.ibm.com/xml/ns/javaee/ibm-ejb-jar-ext_1_0.xsd"
version="1.0">
<session name="RepositoryInstanceFacade">
<resource-ref name="java:app/env/jdbc/MessageManagerDB" isolation-level="TRANSACTION_READ_COMMITTED" commit-priority="2"/>
</session>
</ejb-jar-ext>
Application code to look up the data source and verify that the isolation level from the extensions is being used:
DataSource ds = InitialContext.doLookup("java:app/env/jdbc/MessageManagerDB");
Connection con = ds.getConnection();
try {
int iso = con.getTransactionIsolation();
System.out.println("Isolation level is " + iso);
} finally {
con.close();
}
If the above code outputs 2 (the value of java.sql.Connection.TRANSACTION_READ_COMMITTED), rather than the default isolation level of 4, this demonstrates that the bindings/extensions are being applied.
If after this point, you still don't seeing the commit-priority being honored, then it's a transaction management bug and I recommend reporting it to IBM support.

Related

Project has many errors related to Spring data JPA, and these errors won't go at all

I have a lot of errors in my project and they won't go off and I know that they are related to Dependency related stuff but I'm confused. Can someone tell me how to fix this if you have also faced the same kind of issue?
Try out this one in your XML:
We use JPA namespace for XML based enabling like 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:jpa="http://www.springframework.org/schema/data/jpa"
xsi:schemaLocation="http://www.springframework.org/schema/beans
https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/data/jpa
https://www.springframework.org/schema/data/jpa/spring-jpa.xsd">
<jpa:repositories base-package="path.to.repository.package" />
</beans>

Errors in faces-config after upgrade to JSF 2.2

After upgrading the JSF implementation in our project from Myfaces 1.1 to MyFaces 2.2.12, my IDE (IntelliJ) shows me errors for all navigation-rule and managed-bean entries in my faces-config.xml. I have changed the root element in that file from
<!DOCTYPE faces-config PUBLIC
"-//Sun Microsystems, Inc.//DTD JavaServer Faces Config 1.0//EN"
"http://java.sun.com/dtd/web-facesconfig_1_0.dtd">
<faces-config>
to
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
navigation-rule entries like the following used to work and didn't show any errors before the upgrade:
<navigation-rule>
<navigation-case>
<from-outcome>exampleOutcome</from-outcome>
<to-view-id>/newpages/view1.jsp</to-view-id>
</navigation-case>
</navigation-rule>
After the upgrade to JSF 2.2, the navigation-case element is error-marked with a red underline. When hovering the text with the mouse, I get the error message:
Invalid content was found starting with element 'navigation-case'. One of '{"http://xmlns.jcp.org/xml/ns/javaee":from-view-id}' is expected.
Does this mean the from-view-id has become obligatory with JSF 2.2?
managed-bean entries like
<managed-bean>
<managed-bean-name>ExampleBean</managed-bean-name>
<managed-bean-class>my.example.package.ExampleBean</managed-bean-class>
<managed-bean-scope>session</managed-bean-scope>
</managed-bean>
produce the similar error message:
A field of identity constraint 'faces-config-managed-bean-name-uniqueness' matched element 'faces-config', but this element does not have a simple type.
I haven't found anything about structural changes like this becoming necessary with the upgrade to JSF 2.2. Interestingly, I didn't get this error with an intermediate change to JSF 2.1!
Could anyone point me in a direction that might help this problem?
Try this :
<?xml version="1.0" encoding="UTF-8"?>
<faces-config
xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-facesconfig_2_2.xsd"
version="2.2">
<navigation-rule>
<display-name>first_page.xhtml</display-name>
<from-view-id>/first_page.xhtml</from-view-id>
<navigation-case>
<to-view-id>/second_page.xhtml</to-view-id>
</navigation-case>
</navigation-rule>

Difference between Spring DOCTYPE and <beans> tag

In Spring there is a XML configuration for bean right?
What is the difference between:
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
and
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.0.xsd">
Also i'm a bit curious with the difference between SpringMVC, MVC and just Spring
Difference is in formats of documents definitions. First is called DTD, second - XSD. Both are used to describe possible contents of xml document. DTD is older than XSD. XSD is more flexible and powerful than DTD. More differences you can see here.
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN 2.0//EN"
"http://www.springframework.org/dtd/spring-beans-2.0.dtd">
<beans>
<!-- bean definitions here -->
</beans>
The equivalent file in the XML Schema-style would be…​
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd">
<!-- bean definitions here -->
</beans>
The above Spring XML configuration fragment is boilerplate that you can copy and paste (!) and then plug definitions into like you have always done.
Differences between an XML Schema Definition (XSD) and Document Type Definition (DTD) include: XML schemas are written in XML while DTD are derived from SGML syntax. XML schemas define datatypes for elements and attributes while DTD doesn't support datatypes. ... XML schemas are extensible while DTD is not extensible.

How to add one more dtd to my Spring configration file?

I have use a .dtd to my applicationContext.xml, but now i want to use Spring's AOP based on annotation. I've been told to add a in my applicationContext.xml.
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN" "http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<aop:aspectj-autoproxy />
...
But something wrong happens. It seems that the file doesn't recognize the aop node, so i think i should import one more .dtd file, and i find this:
<!DOCTYPE aspectj PUBLIC
"-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd">
but can i use both .dtd togeter? how?
thx
You don't have to use DOCTYPE here, better declare xml namespaces like this:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd">
<beans>
<aop:aspectj-autoproxy />
...
xmlns="http://www.springframework.org/schema/beans" means that beans will be root namespace (you don't have to use <beans:bean>) and aop will be accesible as desired.
The two DTDs you cite are not constructed in a way that allows them to be used together. In particular, the definition of beans in http://www.springframework.org/dtd/spring-beans.dtd is just
<!ELEMENT beans (
description?,
(import | alias | bean)*
)>
It does not provide for a child named aop:aspectj-autoproxy, and it doesn't provide any mechanism for later users like you to add new things to the content of beans.
DTDs can be built for extensibility and to support the integration of elements from multiple namespaces, though it requires a bit of forethought and planning. When extension points are not included, it's typically pretty hard or impossible to extend the DTD without just rewriting it.

Using spring together with jbossws-cxf on jboss 6

I want to use spring together with jbossws-cxf. Is this possible?
First I tried using jbossws-cxf.xml with bean definitions of spring. The warning message [DescriptorDeploymentAspect] Spring not available, skipping check for user provided jbossws-cxf.xml / cxf.xml configuration files. states that the file gets ignored and means that you should install spring in order for it to not get ignored :-) . So I installed spring for jboss..
After installation and running of a simple MathWS together with a simple WS example I get a
[org.jboss.wsf.stack.cxf.client.configuration.JBossWSSpringBusFactory] INITIAL_APP_CONTEXT_CREATION_FAILED_MSG: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.cxf.binding.soap.customEditorConfigurer' defined in URL [vfs:/D:/lifeDevSuite/jboss/jboss-6.0.0.FinalSpring/common/lib/cxf-rt-bindings-soap.jar/META-INF/cxf/cxf-extension-soap.fixml]: Initialization of bean failed; nested exception is org.springframework.beans.ConversionNotSupportedException: Failed to convert property value of type 'java.util.ArrayList' to required type 'org.springframework.beans.PropertyEditorRegistrar[]' for property 'propertyEditorRegistrars'; nested exception is java.lang.IllegalStateException: Cannot convert value of type [org.apache.cxf.binding.soap.spring.SoapVersionRegistrar] to required type [org.springframework.beans.PropertyEditorRegistrar] for property 'propertyEditorRegistrars[0]': no matching editors or conversion strategy found
error.
My jbossws-cxf.xml looks like this:
`
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
<bean id="mathBean" class="com.sample.MathWS">
<constructor-arg value="alabama" />
</bean>
<jaxws:endpoint id="MathWSX" implementor="#mathBean" address="http://localhost:8080/HelloCXF" />
`
I solved the problem. Sadly - I cannot recall how. And please forgive me - but I'm not going back to try and reproduce it :-)
Basically the answer is "yes". To that specific problem, it may have been a namespace problem, e.g. correct would be
<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:beans="http://www.springframework.org/schema/beans"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xmlns:util="http://www.springframework.org/schema/util"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://cxf.apache.org/jaxws
http://cxf.apache.org/schemas/jaxws.xsd">
It may have been as well that custom spring libraries were deployed (I think it is recommended using the spring libraries coming with jboss and are deployed dynamically automagically)
It may have been something else alltogether

Resources