Implementing EJB timer service on a datasource in an application server - timer

I am migrating my application from JBoss 6 AS to Wildfly 8.2.0. AS. As a part of it, I need to migrate EJB timer service defined on the configured datasource in JBoss 6 AS.
I have gone through the EJB timer service study material and got that it is used to do a job on a schedule basis.
Implementing EJB timer service in datasource in an application server - what does this mean ? In wildfly AS, there is a file timer-sql.properties which requires a syntax change according to the database employed and an entry in standalone-full-ha.xml as mentioned below.
timer-service thread-pool-name="timer" default-data-store="clustered-store">
<data-stores>
<database-data-store name="clustered-store" datasource-jndi-name="java:/TestDB" partition="timer"/>
</data-stores>
</timer-service>
I would like to understand more on the same and hence, can anyone please explain what the EJB timer service configured on a datasource in an application server does and how it works at a high level. Also, please suggest any link that explains the same. Thanks.

Related

How to test Spring database down?

I have this SpringBoot server app using PostgreSQL database if it's up and sending error response if it's down. So my app is running regardless the database connection.
I would very much like to test it (jUnit / mockmvc).
My question is very simple, yet I did not find the answer online:
how does one simulate a database connection loss in SpringBoot?
If anyone wants, I can supply code (project is up at https://github.com/k-wasilewski/workshop/)
Have you thought of Testcontainers? You can spin up your docker image through a Junit test and make your spring boot use that as your database.
Since you use junit, you can start/stop this container at will.
This will generate a test which creates the condition you are looking for and write code as to what to expect when the database is down.
Here are some links to get started,
Testcontainers and Junit4 with Testcontainers quickstart - https://www.testcontainers.org/quickstart/junit_4_quickstart/
Spring boot documentation - Use Testcontainers for integration testing
https://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#howto-testcontainers
Testcontainer github link example for springboot app
https://github.com/testcontainers/testcontainers-java/tree/master/examples/spring-boot
Testcontainer - Generic container javadoc. You can find methods for start/stop
container here. call from your Junit.
https://javadoc.io/static/org.testcontainers/testcontainers/1.12.4/org/testcontainers/containers/GenericContainer.html
You can implement your own Datasource based on DelegatingDataSource and then let it throw exceptions instead of delegating when ever you want to.
I've done this before by creating a Spring Boot test configuration class that created the DataSource and wrapped it in a Java proxy. The proxy simply passed method calls down to the underlying DataSource, until a certain flag was set. Once the flag was set, then any method called on the proxy would throw an exception without calling the underlying DataSource. Essentially, this allowed me to "bring the database down" or "up" simply by flipping the flag.

How to select a database in run time using spring boot

I have created an application with 2 databases. I need to select one of them in run time. Is there any method or class in spring boot.
You can do it using application.properties configurations. You don't need to restart the server for those configurations to act.
Please refer to:
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-external-config.html
spring.datasource.url=jdbc:mysql://localhost/test
spring.datasource.username=dbuser
spring.datasource.password=dbpass
spring.datasource.driver-class-name=com.mysql.jdbc.Drive
https://docs.spring.io/spring-boot/docs/current/reference/html/boot-features-sql.html

JNDI datasource and ApplicationModule tester

I have an ADF application module and I have it configured to use a JNDI datasource (e.g., JNDI name = jdbc/ORCL).
That all works fine, but when I try to test my Application Module through the integrated tester in JDeveloper (i.e., run the application module directly instead of running a page), it cannot find the JNDI data source, even if my integrated Weblogic Server is started.
Is this just a drawback of using JNDI: that you cannot use the integrated application module tester anymore? Or is there a way to configure JDeveloper to make this all work together (JNDI + integrated AM tester)?
You should make use of the default JDBC url, i.e. java:comp/env/jdbc/ORCL instead of using the short form jdbc/ORCL. Many features of JDeveloper rely on the full url to work. For example, even if you don't manually create the datasource on your Integrated WebLogic Server, you still can right-click and run a page to test because behind the scene, JDeveloper automatically create a temporary datasource with that name to run the application.
When you deploy your application to an actual standalone server, the application will automatically trim the java:comp/env/ portion of the full url and look for the datasource with the name jdbc/ORCL. You don't need to shorten it yourself :).

Hangfire configuration for SQL Server

I am coding a MVC 5 internet application, and am wishing to use Hangfire for recurring tasks.
How can I setup Hangfire to use SQL Server storage without specifying this in the Startup.Auth ConfigureAuth(IAppBuilder app) function.
Here is a resource link for SQL Server configuration: http://docs.hangfire.io/en/latest/configuration/using-sql-server.html
This resource states that:
If you want to use Hangfire outside of web application, where OWIN
Startup class is not applicable, create an instance of the
SqlServerStorage manually and pass it to the JobStorage.Current static
property. Parameters are the same.
The example code is as follows:
JobStorage.Current = new SqlServerStorage("connection string or its name");
I have tried the following code (with my own connection string), yet the dashboard is not available. I have called the code above from a controller function.
Is there something that I have not done correct? How can I setup Hangfire to use SQL Server storage without using the Startup.Auth class?
Thanks in advance.
I think this is your problem:
I have called the code above from a controller function.
You should be setting this up once on application startup - either in the Configuration method of an OWIN Startup class (followed by an app.UseHangFireServer();), or in the Application_Start method of your Global.asax.cs if you really don't want to use OWIN. Either way, the line you're looking for is right there in the documentation you reference:
Hangfire.GlobalConfiguration.Configuration.UseSqlServerStorage(#"connection string or connection string name");
HOWEVER, as far as I know, if you want to use the dashboard you must configure that part via OWIN along with an authorization filter. See http://docs.hangfire.io/en/latest/configuration/using-dashboard.html
So really, I don't know if any downside of using the OWIN configuration for all of this. It's the more modern platform, and since you mention this is for an MVC5 app it's unlikely that you have legacy concerns.

Sitecore Active Directory Module

Currently we have our Active Directory (LDAP) domain controller defined in the ConnectionStrings.config file. Is it possible to configure a second domain controller, as a fail-over option?
For example, recently Domain Controller 1 failed, and I had to manually change the connection string to point to Domain Controller 2 - but the website was generating errors in the mean-time (for several hours of down-time).
We are running Sitecore version 6.5
(Sitecore.NET 6.5.0 (rev. 120706) )
No, it's not possible to configure a fail-over partner.
You could put a loadbalancer in between the two domain controllers.
You could actually do that. There are options with the AD module that allow for connecting to multiple domains and/or using multipe providers. All pipelines in Sitecore are extendable, so there's nothing to stop you from setting this up. You could easily do some custom coding to catch exceptions during login and switch to a different provider. The trick is just doing the custom coding.

Resources