Configure a connection retry for a Redis instance - symfony

I plan to move my web site to a cloud one. I've been told there is some micro-interruptions in some services.
Therefore I'd like to configure a connection retry for the redis cache set up.
I'm using Symfony 4.2 with this configuration
framework:
cache:
app: cache.adapter.redis
default_redis_provider: '%env(REDIS_URL)%'
Is there any way to configure the retry_interval option of redis in Symfony ?
EDIT : including precisions of #simon.ro

Redis has an option retry_interval which you can specify at connect-time. You should check the documentation of the redis connecting library you are using.

The default_redis_provider is a DSN that will be parsed with parse_url function
So you can add parameters into query string like this :
default_redis_provider: 'redis://u:pass#localhost/2:6379?retry_interval=300&timeout=10&read_timeout=30&tcp_keepalive=10'
path of url /2 is the dbindex of redis

Related

Untrusted Certificate Error when connecting to SQL Server running in Docker from .NET 7 API in VS2022

I have an API which I've upgraded from .NET Core 3.1 to .NET 7. It's now throwing an error when trying to connect to the database.
The error is:
A connection was successfully established with the server, but then an error occurred during the login process. (provider: SSL Provider, error: 0 - The certificate chain was issued by an authority that is not trusted.
I'm using VS2022, SQL Server (mcr.microsoft.com/mssql/server:2022-latest) is running in a Docker container.
I'm using Docker Compose:
version: '3.9'
services:
sql-server-db:
image: "mcr.microsoft.com/mssql/server:2022-latest"
container_name: sql-server-db
environment:
MSSQL_SA_PASSWORD: "P#ssw0rd"
ACCEPT_EULA: "Y"
ports:
- "1433:1433"
volumes:
- sql1:/var/opt/mssql
volumes:
sql1:
external: false
The connection string is
server=127.0.0.1,1433;Initial Catalog=xxx;user id=sa;password=P#ssw0rd;Encrypt=False;TrustServerCertificate=True
From the posts I've read, either Encrypt=False or TrustServerCertificate=True should fix this issue, but neither, or indeed, both have helped.
I have confirmed that the SQL Server instance is running ok, I can connect using SSMS, using the username and password from the connection string.
Further, I can confirm that it's working with .NET 6, so it is definitely an issue with .NET 7 & EntityFrameworkCore 7.
I only added "Trust Server Certificate=True" to my connection string after I updated my app. Try to remove "Encrypt=False".
As I previously mentioned on your Mastodon post, that's a catch-all error message for several issues.
I solved it by using the standard volume for persistence, another person mentioned on a GitHub issue that I saw that they solved it by applying the password requirements (I think they are at least 8 characters with at least one lowercase, at least one uppercase, at least one number and at least one symbol).
I have managed to fix the issue.
I changed my repositories to inject a IDbContextFactory<> and create a DbContext, rather than inject a DbContext object directly.
public BookRepository(IDbContextFactory<SampleAPIContext> dbContextFactory, IRestToLinqParser<Book> parser, ILogger<BookRepository> logger) : base(dbContextFactory, parser, logger)
{
}
and changed my Startup.cs to add the IDbContextFactory rather than the DBContext
services.AddDbContextFactory<SampleAPIContext>(
options => SqlServerDbContextOptionsExtensions.UseSqlServer(options, connectionString)
);
I'm not entirely sure why this made the difference, but it did.

What is the configuration to make rabbitmq api and management plugin accessible from the web?

Trying to find a solution for opening RabbitMQ to the internet is not exactly easy. The documentation is sparse and the configuration I can find is in multiple formats. How can I configure RabbitMQ to allow external access?
There are 3 ways to configure RabbitMQ: command line and two styles of configuration file. Here is how to configure RabbitMQ using one of the configuration styles.
First you'll need to find the rabbitmq.config. It is found in the RabbitMQ installation directory. I found mine here:
C:\Users\[User]\AppData\Roaming\RabbitMQ\rabbitmq.config
The config file follows a very particular syntax. You'll need to take care. After a configuration change you will need to restart RabbitMQ for the configuration to take affect. If RabbitMQ stops immediately there is a problem with your configuration.
If RabbitMQ runs this only means that the configuration didn't kill the process. It does not mean that it was applied correctly. It will certainly apply if you get the syntax correctly, but every wrong configuration does not guarantee the service crashes.
Follows are a few example configurations (notice the trailing ".") :
Base of the RabbitMQ configuration style we will be using (should only appear once in the configuration file):
[{rabbit, []}].
Configuration that allows the RabbitMQ management plugin to be accessed from the internet:
[{rabbit,
[
{rabbitmq_management, [{listener, [{port, 15672}]}]},
{rabbitmq_management, [{cors_allow_origins, ["*"]}]}
]
}].
Configuration that allows the RabbitMQ api to be accessed from the internet:
[{rabbit,
[
{tcp_listeners, [5672]}
]
}].
Configuration that allows guest user to access the management plugin from the internet:
[{rabbit,
[
{loopback_users, []},
{rabbitmq_management, [{listener, [{port, 15672}]}]},
{rabbitmq_management, [{cors_allow_origins, ["*"]}]}
]
}].
Configuration that does all of the above:
[{rabbit,
[
{tcp_listeners, [5672]},
{loopback_users, []},
{rabbitmq_management, [{listener, [{port, 15672}]}]},
{rabbitmq_management, [{cors_allow_origins, ["*"]}]}
]
}].
Leaving a trailing comma in an array in your configuration will cause RabbitMQ to stop.
If you are still having issues check that you've permitted the ports through any firewalls.
Considerations This leaves your RabbitMQ server wide open. You will want to certainly restrict the access. A search of tcp_listeners will reveal other options to restrict access to particular ip. It is also not a good idea to expose the default guest user to the internet in any production environment.

How to specify Logout Service in the PingFederateSLOURL in mod_pf configuration

We are using PingFederate as Service Provider and are using Opentokenadapter.
We are also using mod_pf apache library provided by PingFederate.
Is there any way we can configure "Logout Service (present in OpenToken Adapter )" in the mod_pf configuration? Is there any query parameter for it just like we have for PartnerIdpId, TargetResource etc?
The Apache Integration Kit's mod_pf.conf refers to the /sp/startSLO.ping application endpoint. In that configuration file is where you will configure various bits for the integration... You can review the /sp/startSLO.ping options as listed here:
https://documentation.pingidentity.com/pingfederate/pf81/index.shtml#concept_spServices.html#concept_spServices
The "Logout Service", as defined in the adapter, is where the browser will be sent to for an SLO that will destroy any current session within the SP Application. By spec, that application must return BACK to PingFederate, so that PingFederate can respond back to the IdP with a success/fail. If you plan to support SLO, then this "service" must exist. It's "goal" will be close the session, and redirect back to PingFederate with a success.

Unable to connect to remote MySql server in Asp.Net

I needed to connect to MYSQL databases via asp.net. I am using MySQL Connector to make connection with database but while doing this I am having this Error:
Authentication with old password no longer supported, use 4.1 style passwords.
From MySQL 4.1 and higher they use a new protocol that is not compatible with earlier versions. Which is why when you upgrade the server from an earlier version to 4.1 or higher you receive the authentication error message.
If you need to connect to the database with both clients before and after version 4.1 you must have two passwords stored. One the old way and one the new way.
You can set a users password to the new way using:
SET PASSWORD for <username> = PASSWORD('new password')
SET PASSWORD FOR 'steve'#'10.15.2.67' = PASSWORD('my secure password');
If needed you can also set passwords to the old way using:
SET PASSWORD for <username> = OLD_PASSWORD('new password')
SET PASSWORD FOR 'steve'#'10.15.2.67' = OLD_PASSWORD('my secure password');
There is a great page in the MySQL manual which will detail the process
You can actually for the server if newer than 4.1 to still use the old password method however this isn't recommended.
To do this, you can start the server with the --old-passwords option.
So, either the server has updated and you're using a old client - or you've updated your client (which now uses the new password system) and your connecting to a server below 4.1
ok but if you do not have the authorization to do this,simply because you are in a shared hosting environment:
SET PASSWORD for <username> = OLD_PASSWORD('new password')
SET PASSWORD FOR 'steve'#'10.15.2.67' = OLD_PASSWORD('my secure password');
What can you do?
I have not found a workaround and my hosting provider has changed the mysql configuration without warning...nor giving solutions.
UNCOMPLETE SOLUTION
You can force the web.config to use the old connector. It seems to work, but mysql errors occur... so I think there is a bug somewhere in the connectors.

Can I define a new connection / Entity manager within a Bundle configuration?

I am trying to define a Bundle that helps to index some data (from an Entity) within a sqlite fts table, in order to do some full-text search.
I know I can define alternate connection and Entity Manager using the app config file (like shown in the cookbook), but I was wondering if it was possible to do so within the bundle configuration - by defining, for example, a service with the doctrine service injected, so that it can instantiate a new connection.
Sqlite is not mandatory, it can be any database type (supported by doctrine).
Thanks in advance for your help.
I would suggest looking at FOSUserBundle for how they handle multiple persistence layers (ORM, Couch, MongoDB). You would essentially be doing the same thing. It's just a matter of loading different configurations depending on the driver specified in app/config/config.yml.
As far as i know it it not possible. Also database connections should be managed centralized in app/config.yml.
I would suggest to define the connection there and add a configuration option to you bundle where you can specify wich connection to use for the indexing stuff.
# app/config.yml
doctrine:
dbal:
default_connection: default
connections:
default:
dbname: database
host: localhost
user: user
password: secret
driver: pdo_mysql
my_data_index:
dbname: database
driver: pdo_sqlite
# configuration option of you bundle
acme_indexer:
connection: my_data_index
Then in your bundle you can read this config option and obtain the connection/entity manager and inject it into your indexing service.
Edit:
You can for sure create a custom connection programaticly in your bundle
$params = array(
'driver' =>'pdo_sqlite',
....
);
$factory = $container->get('doctrine.dbal.connection_factory')
$connection = $factory->createConnection($params);
But as i said before it is bad practice because you would evade the symfony standart way of defining database connections.

Resources