Spring JPA sql-pool - Reset (readOnly) on connection on a few table - spring

In my logs file, while querying a certain table it logs:
2022-06-07 17:16:31,404 [pool-10-thread-69] DEBUG [PoolBase] [REF=""] - sql-pool - Reset (readOnly) on connection ConnectionID:9 ClientConnectionId: 11c28ad4-4ceb-486e-952a-789675916ca9
I can't find it online that what does sql-pool - Reset (readOnly) on connection ConnectionID mean.

Referring to this code of Hikari, it means that the Connection Pool is resetting the state of readOnly configuration. It can be from true to false or vice versa. These are the list of reset states:
private static final String[] RESET_STATES = {"readOnly", "autoCommit", "isolation", "catalog", "netTimeout", "schema"};
I get rid of this by setting the readOnly as false in the application.properties because in my case it reset from true to false. So when I set it to false in the properties, will prevent it from getting reset
spring.readonly.datasource.hikari.read-only=false

Related

How to migrate from deprecated EmbeddedJMS to recommended EmbeddedActiveMQ

I have a Spring Boot app with an embedded queue. I'm using the spring-boot-starter-artemis dependency and trying to upgrade my Java app.
I could not find any guide, and a few things are not clear, e.g.:
Checking if a queue exist
EmbeddedJMS:
jmsServer.getJMSServerManager().getBindingsOnQueue(queueName).length > 0
Can it be:
jmsServer.getActiveMQServer().isAddressBound(queueName)
or maybe:
jmsServer.getActiveMQServer().bindingQuery(SimpleString.toSimpleString(queueName)).isExists()
Creation of queue:
jmsServer.getJMSServerManager().createQueue(true, queueName, null, true, queueName)
with params (boolean storeConfig, String queueName, String selectorString, boolean durable, String... bindings)
Is it the same like:
QueueConfiguration queueConfiguration = new QueueConfiguration(queueName);
queueConfiguration.setDurable(true);
return jmsServer.getActiveMQServer().createQueue(queueConfiguration, true).isEnabled();
(added)
Getting address:
jmsServer.getJMSServerManager().getAddressSettings(address);
is the same like:
jmsServer.getActiveMQServer().getAddressSettingsRepository().getMatch(address);
Not sure how migration Connection Factory settings
final Configuration jmsConfiguration = new ConfigurationImpl();
jmsConfiguration.getConnectionFactoryConfigurations()
.add(new ConnectionFactoryConfigurationImpl()
.setName("cf")
.setConnectorNames(Collections.singletonList("connector"))
.setBindings("cf"));
embeddedActiveMQ.setConfiguration(jmsConfiguration);
To check if a queue exists I think the simplest equivalent solution would be:
server.locateQueue("myQueue") != null
To create a queue the simplest equivalent solution would be:
server.createQueue(new QueueConfiguration("myQueue")) != null
The queue will be durable by default so there's no reason use setDurable(true).
To get address settings you use this (as you suspect):
server.getAddressSettingsRepository().getMatch(address);
Regarding connection factories, you don't actually need to configure connection factories on the broker. You simply need to configure the properties for the InitialContext for your JNDI lookup. See this documentation for more details on that.

Getting an err status 500 connecting reactmongo to mlabs

SOLUTION in the bottom
i'm trying to connect my reactive spring webflux project to mongodb via mlabs. But from the api and documentation i don't know which method is causing my problem. I set up two methods to work with my mlab db but don't know which should I stick to.
Method 1 > in the application properties set up my mlab uri
spring.data.mongodb.uri=mongodb://<fernando>:<password>#ds261277.mlab.com:61277/cont-api?AuthMechanism=SCRAM-SHA-1
i've tried lower case, with & ampersand instead of question mark and adding
spring.data.mongodb.database=mycollection
Result: My code runs but when i make any request(get, post, etc) i get an error, adding or removing the "?AuthMechanism=SCRAM-SHA-1" doesn't make a difference
ERROR 2423 --- [ntLoopGroup-2-2] a.w.r.e.AbstractErrorWebExceptionHandler : [eb675923] 500 Server Error for HTTP POST "/content/v1/cont/"
org.springframework.data.mongodb.UncategorizedMongoDbException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='<fernando>', source='cont-api', password=<hidden>, mechanismProperties={}}; nested exception is com.mongodb.MongoSecurityException: Exception authenticating MongoCredential{mechanism=SCRAM-SHA-1, userName='<fernando>', source='cont-api', password=<hidden>, mechanismProperties={}}
Method 2 > create a dataConfig like so, but when i run, i get an error of trying to connect to local mongodb
#Configuration
public class DataConfig {
private static final String DATABASE_NAME = "hospitals";
private static final String DATABA_URL = "mongodb://<fernando>:<password>#ds261277.mlab.com:61277/cont-api";
MongoClient mongoClient = MongoClients.create(new ConnectionString(DATABA_URL));
MongoDatabase database = mongoClient.getDatabase(DATABASE_NAME);
// #Bean
// public ReactiveMongoDatabaseFactory mongoDatabaseFactory(MongoClient mongoClient){
// return new SimpleReactiveMongoDatabaseFactory(mongoClient, DATABASE_NAME);
// }
//
// #Bean
// public ReactiveMongoOperations reactiveMongoTemplate(ReactiveMongoDatabaseFactory database){
// return new ReactiveMongoTemplate(database);
// }
}
Results:
[localhost:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
any help would be great, thanks in advance
UPDATE & SOLUTION :
So i scrapped method two and stuck to method one, i just had to remove the angle brackets from the mlab uri so instead of it's now //fernando:password ...
So heads up to anyone using mlab, completely forgot to remove the angle brackets < >
Before:
spring.data.mongodb.uri=mongodb://<fernando>:<password>#ds261277.mlab.com:61277/cont-api
After: without < > around the user and password
spring.data.mongodb.uri=mongodb://fernando:password#ds261277.mlab.com:61277/cont-api

MQQueueManager: What to expect from isConnected state after creation, during use?

I inherited this lovely bit of code below.
The way I read it the developer makes three assumptions:
An MQQueueManager instance is not necessarily created in a state where isConnected() returns true
If it is created in state isConnected() == false, the state might change "later", hence the timeout code
If you try to create an access queue from a disconnected MQQueueManager, it will not throw an exception.
What I would expect is that an MQQueueManager instance is created in state isConnected() == true, that this state might change later (network failure etc), and that this state change (isConnected() == false) would cause an operation on the queue to fail with an MQException.
The documentation is delightfully silent on these points, except to note that the only way to reconnect to a queue after manually disconnecting the MQQueueManager is to create a new instance of MQQueueManager.
Who can set me straight here?
qMgr = new MQQueueManager( qManager );
// Set up the options on the queue we wish to open...
// Note. All WebSphere MQ Options are prefixed with MQC in Java.
final int openOptions = MQC.MQOO_INPUT_AS_Q_DEF | MQC.MQOO_OUTPUT;
// Now specify the queue that we wish to open,
// and the open options...
queue = qMgr.accessQueue( queueName, openOptions );
// Set the get message options...
final MQGetMessageOptions gmo = new MQGetMessageOptions(); // accept the
// defaults
gmo.options = MQC.MQGMO_WAIT;
gmo.waitInterval = 1000;
connectionStatus = CONNECTING;
int timeOutCounter = 0;
while(!qMgr.isConnected()) {
InboundMsgTask.sleep(1000);
timeOutCounter++;
if(timeOutCounter > 4) {
connectionStatus = TIME_OUT;
return;
}
}
connectionStatus = CONNECTED;
Instead of checking the IsConnected==True, it is better to go ahead make the actual MQ .NET method call (Get, Put etc). If the connection is broken these calls would throw a connection broken execption (MQRC 2009). Remember the IsConnected could be True before a MQ method is called but it can change during the execution of a MQ method. Your code needs to handle the connection broken exception and call the MQQueueManager.Disconnect method and then re-establish the connection. The Disconnect call would free up any resources allocated and close all gracefully any queue manager objects that were opened. Ignore any exception thrown by the Disconnect method.
If you are using MQ v7.1 or v7.5, then the .NET client can automatically reconnect to queue manager if it detects connection errors. You will need to enable the automatic reconnect option. Please see the MQ InfoCenter.
EDIT:
A new MQQueueManager() will return an instance of MQQueueManager class if connection to queue manager is successfully established. In case of errors, a MQExceptionwill be thrown. There is no need to wait for connection to complete as MQQueueManager constructor is a blocking call.

Failed to connect to an IPC Port: The system cannot find the file specified

In my .net 2.0 application Remote object suddenly destroyed and thrown the below exception.
"Failed to connect to an IPC Port: The system cannot find the file specified."
I have IPC remoting server and which create a singleton object.
i have override the InitializeLifetimeService() method and returns null for infinite lifetime.
server and client applications are working fine but some times we got the above exception.
serverCode:
//create and register the processheartbeat.
BinaryServerFormatterSinkProvider serverprovider = new BinaryServerFormatterSinkProvider();
serverprovider.TypeFilterLevel = System.Runtime.Serialization.Formatters.TypeFilterLevel.Full;
//Hosts the Heartbeat object and registers it.
processHeartbeatChn = new IpcServerChannel("HeartbeatChannel", "localhost:" + applicationHeartbeatPort, serverprovider);
//registers the channel
ChannelServices.RegisterChannel(processHeartbeatChn, false);
//register the service
RemotingConfiguration.RegisterWellKnownServiceType(typeof(Heartbeat),
appName, WellKnownObjectMode.Singleton);
ClientCode:
string uri = string.Format(CultureInfo.InvariantCulture,"ipc://localhost:{0}/{1}", applicationHeartbeatPort, appName);
//get the Heartbeat object
remoteHeartbeat = (Heartbeat)Activator.GetObject(typeof(Heartbeat), uri);
any hot fix is there to resolve this problem?
can any one help me an this?

SignalR 0.5.2 - Context.User is null on disconnect

I recently updated to SignalR 0.5.2 from 0.4.0 in my ASP.NET MVC3 application. In SignalR 0.5.2 the "User" property on the Context instance is null when the user disconnects - is this by design?
As seen from the "Immediate Window" snapshot below, all I know about the Context when a client disconnects is the disconnecting client's ConnectionId.
Context
{SignalR.Hubs.HubCallerContext}
ConnectionId: "... some connection id ..."
Headers: null
QueryString: null
RequestCookies: null
ServerVariables: null
User: null
Simplified, my SignalR Hub implementation looks like this:
public class MyHub : Hub, IDisconnect, IConnected
{
// some other code
public Task Disconnect()
{
var user = Context.User; // <-- This is null
// more code
}
}
To sum up - am I forgetting something here or is it by design that Context.User is null? And if so - why? :)
I found the answer in the SignalR wiki. In its section about hubs ( https://github.com/SignalR/SignalR/wiki/Hubs ) it states:
Whenever a client disconnects, the Disconnect method will be invoked on all hubs that implement IDisconnect. When this method is called you can use Context.ConnectionId to access the client that disconnected.
NOTE: This method is called from the server, that means state on the Caller object, any state that was with the connection, as well as the HubContext's User and Cookies will not be populated.

Resources