I'm working on
Symfony 5.3
Mercure bundle 0.3.4
php 8.1
I would like to bind my API with my mercure HUB, I use the mercure bundle 0.3.4, and in my mercure.yaml I'm trying to change the algorithm to 'rsa.sha256' but everytime I update an entity bound with mercure (annotations mercure: true), I get an error thrown that say:
It was not possible to parse your key, reason: error:0909006C:PEM
routines:get_name:no start line
Here is my mercure.yaml:
mercure:
hubs:
default:
url: '%env(MERCURE_URL)%'
public_url: '%env(MERCURE_PUBLIC_URL)%'
jwt:
secret: '%env(MERCURE_JWT_SECRET)%'
publish: ['*']
subscribe: ['*']
algorithm: 'rsa.sha256'
I think there might be a situation with the private and the public key but I can't figure out how to solve this...
Does anyone know how to help me ?
Related
I am looking to use Mercury with RabbitMQ. This is the first time that I have used Mercury as well as RabbitMQ so I am not yet good.
Here is where I am:
I've installed Mercure, and Messenger.
Messenger.yaml
framework:
messenger:
# Uncomment this (and the failed transport below) to send failed messages to this transport for later handling.
failure_transport: failed
transports:
# https://symfony.com/doc/current/messenger.html#transport-configuration
async: '%env(MESSENGER_TRANSPORT_DSN)%'
failed: '%env(MESSENGER_TRANSPORT_FAILED_DSN)%'
# sync: 'sync://'
routing:
# Route your messages to the transports
# 'App\Message\YourMessage': async
.env:
MERCURE_PUBLISH_URL=http://localhost:3000/.well-known/mercure
MERCURE_JWT_TOKEN=aVerySecretKey
MESSENGER_TRANSPORT_DSN=amqp://bastien:mypassword#localhost:5672/%2f/messages
MESSENGER_TRANSPORT_FAILED_DSN=amqp://bastien:mypassword#localhost:5672/%2f/failed
And in my controller I simulated 50 pings on a URL of my local app:
/**
* #Route("/ping", name="ping", methods={"POST"})
*/
public function ping(MessageBusInterface $bus)
{
for($i=0;$i<=50;$i++)
{
$update = new Update("http://monsite.com/ping", "[]");
$bus->dispatch($update);
}
return $this->redirectToRoute('home');
}
I have successfully started my instance of Mercury as well as that of Messenger which is therefore well connected to my RabbitMQ.
But when I test sending the pings, it works, but without going through my RabbitMQ. Did I miss something? I think of my Messenger.yaml in the routing part but I don't know what to put if it is the case
By default, messages are executed synchronously in messenger.
You will need to configure the Update message in the messenger.yaml to use the async transport:
Symfony\Component\Mercure\Update: async
I´m working in a localhost server with Symfony 4 and FOSUserBundle. I can't manage to receive the email confirmation when a new user is registered.
I have tried the following post but it´s not working in my case:
Symfony 4 SwiftMailer Gmail : Email not sent
I have tried to configure SwiftMailer to send using gmail smtp server and mailtrap smtp server without success. Also I have checked dev.log and no errors are found.
I´m not sure which is the right file to configure Swift Mailer (.env or packages/dev/swiftmailer.yaml). Right now the configuration is the following:
.env file:
MAILER_URL=gmail://***#gmail.com:***#localhost
swiftmailer.yaml:
swiftmailer:
transport: gmail
username: ***#gmail.com
password: ***
host: localhost
port: 465
encryption: ssl
auth-mode: login
spool: { type: 'memory' }
stream_options:
ssl:
allow_self_signed: true
verify_peer: false
verify_peer_name: false
Any ideas? It´s not mandatory to use gmail as the smtp server.
Thanks beforehand.
SOLUTION:
The problem was in the /config/test/fos_user.yaml file:
I changed:
service:
mailer: 'fos_user.mailer.noop'
To:
service:
mailer: 'fos_user.mailer.default'
Documentation: http://symfony.com/doc/master/bundles/FOSUserBundle/emails.html
Also I have accepted less secure connections from the gmail account setting in order to work.
I had the same problem with Symfony 4. My packages version
swiftmailer/swiftmailer v6.1.0
symfony/swiftmailer-bundle v3.2.2
When I used configuration:
swiftmailer:
url: '%env(MAILER_URL)%'
spool: { type: 'memory' }
The emails were not send and no exception occurred.
Then I change the settings into:
swiftmailer:
url: '%env(MAILER_URL)%'
spool:
type: 'file'
path: '%kernel.cache_dir%/swiftmailer/spool'
And tried command:
php bin/console swiftmailer:spool:send --env=dev -vvv
And I saw the error:
[Swift_SwiftException]
No IDN encoder found (install the intl extension or the true/punycode package
So I installed true/punycode package via:
composer req true/punycode
and now emails are sending fine also with spool memory.
Default behaviour of Symfony mailer is to send the email messages immediately, but as you configured, it will "spool" the emails instead of sending them directly.
spool: { type: 'memory' }
Sending the messages from the spool is done separately, with a console command:
php bin/console swiftmailer:spool:send --env=dev
#see more docs here
UPDATE:
As #nek said on the first comment, the the memory spool send the mail immediately (if none exception occured). The spool:send command is only required when using the file spool.
I have installed FOSElasticaBundle to handle search and used the following configuration:
fos_elastica:
clients:
default: { host: localhost, port: 9200 }
indexes:
search:
client: default
types:
post:
mappings:
postTitle: ~
postContent: ~
persistence:
driver: orm
model: Shop\Bundle\ManagementBundle\Entity\Post
provider: ~
listener: ~
finder: ~
Search is working fine, but when I try to login a user, he is succesfully logged in but I get a redirection to login_check route with the following error:
ContextErrorException: Catchable Fatal Error: Argument 1 passed to
FOS\ElasticaBundle\Doctrine\Listener::postUpdate() must be an instance
of Doctrine\Common\Persistence\Event\LifecycleEventArgs, instance of
Doctrine\ORM\Event\LifecycleEventArgs given, called in
C:\xampp\htdocs\community\vendor\symfony\symfony\src\Symfony\Bridge\Doctrine\ContainerAwareEventManager.php
on line 63 and defined in
C:\xampp\htdocs\community\vendor\friendsofsymfony\elastica-bundle\Doctrine\Listener.php
line 111
If I am not wrong, the login_check path is updating the record of the user (precisely the last_login_date field in user table) which triggers the postUpdate() lifecycle event. But I can't resolve the issue. Yout help is appreciated.
PS: I am using FOSUserBundle for users storage in database.
Edit: the above issue happens for other entities persistence lifecycle events (preRemove()...) as well.
I am trying to use syfmony2 framework with RabbitMqBundle from here
I am sure that my rabbitmq server is up and running and I am doing the configuration and publishers code accordingly to the docs delivered on github. Unfortunately I can`t add any message to the queue.
I am sure that my rabbitmq server is up and running. I have queue named accordingly to the symfony configuration file.
Have anyone got any clue what is wrong?
Thanks in advance for any suggestions.
well... try this simple example
# app/config.yml
old_sound_rabbit_mq:
connections: %rabbitmq_connections%
producers: %rabbitmq_producers%
consumers: %rabbitmq_consumers%
parameters:
# connection parameters
rabbitmq_connections:
default: { host: 'localhost', port: 5672, user: 'guest', password: 'guest', vhost: '/' }
# define producers
rabbitmq_producers:
sample:
connection: default
exchange_options: {name: 'exchange_name', type: direct, auto_delete: false, durable: true}
# define consumers
rabbitmq_consumers:
sample:
connection: default
exchange_options: {name: 'exchange_name', type: direct, auto_delete: false, durable: true}
queue_options: {name: 'sample', auto_delete: false}
callback: rabbitmq.callback.service
then you should define your callback service. feel free to put it in app/config.yml
services:
rabbitmq.callback.service:
class: RabbitMQ\Callback\Service
and yes. you should write this callback service. here is simple implementation. should be enough for understanding and check is it works for you.
namespace RabbitMQ\Callback;
use OldSound\RabbitMqBundle\RabbitMq\ConsumerInterface;
use PhpAmqpLib\Channel\AMQPChannel;
use PhpAmqpLib\Message\AMQPMessage;
class Service implements ConsumerInterface
{
public function execute(AMQPMessage $msg)
{
var_dump(unserialize($msg->body));
}
}
then you should start rabbitmq server, run consumer and check was new exchange and queue added.
to run test consumer you should run
app/console rabbitmq:consumer sample --route="sample"
in your controller (where you want to send message to rabbitMQ put next code
# get producer service
$producer = $this->get('old_sound_rabbit_mq.sample_producer');
# publish message
$producer->publish(serialize(array('foo'=>'bar','_FOO'=>'_BAR')), 'sample');
Hope it's more or less clear and will help you with rabbitmq.
PS: it's easier to debug if you have rabbitmq management plugin. if you have no, use console commands like rabbitmqctl to check queues/exchanges/consumers and so on...
and also would be nice to see your configuration for producers/consumers. callback services code as well.
I also had some issue to send messages with this bundle, i recommend you to try SonataNotificationBundle instead.
You can also install the RabbitMq management plugin to see the queued messages.
UPDATE: problem solved, see the comments (many issues, the versions differences was but one of them).
I'm trying to configure sessions in Symfony2 in config.yml file. I have the following configuration:
session:
default_locale: %locale%
lifetime: 7200
auto_start: true
storage_id: session.storage.pdo
parameters:
pdo.db_options:
db_table: session
db_id_col: session_id
db_data_col: session_value
db_time_col: session_time
services:
pdo:
class: PDO
arguments:
- "mysql:dbname=%database_name%"
- %database_user%
- %database_password%
session.storage.pdo:
class: Symfony\Component\HttpFoundation\SessionStorage\PdoSessionStorage
arguments: [#pdo, %session.storage.options%, %pdo.db_options%]
It's based on Symfony2's cookbook http://symfony.com/doc/2.0/cookbook/configuration/pdo_session_storage.html
I've created exactly the same table as in the given link.
However, it doesn't work. I get some "blank" error (no error message, but "PDO Exception" and "Error Exception"). I admit I have no much knowledge on configuring the Symfony2 or any info (that's why I'm using cookbook). I lost a lot of time and see no much documentation about it in the internet, not mentioning the fact that internet is quite silent about this case (having session storaged to DB table in Symfony2).
My NetBeans is "shouting" sth about the last line:
arguments: [#pdo, %session.storage.options%, %pdo.db_options%]
"ScannerException while scanning for the next token we had this found character #(64) that cannot start any token".
UPDATE:
Hmm now I'm not sure if it's about the configuration. I can see that Symfony2's cookbook (use... ) example doesn't match actually the file structure in the Symfony2's bundle. In a word, there is no such file-path, but after putting the real one it still doesn't work.
I had the same problem as you with Symfony 2.5. Turns out my solution was to disable session.auto_start in php.ini. The PdoSessionStorage will not take over if the session is being started before PDO has the opportunity to take control of it. I had overlooked this at first because I was modifying the wrong one (I had two copies of php.ini). To check if this is the problem on yours, run this command:
echo ini_get('session.auto_start');
If that returns a '1' or a 'true', then be sure to set this in your php.ini:
session.auto_start = 0
So for reference, here is my setup with Symfony 2.5 to make this work:
config.yml
framework:
session:
handler_id: session.handler.pdo
parameters:
pdo.db_options:
db_table: session
db_id_col: session_id
db_data_col: session_value
db_time_col: session_time
services:
session.handler.pdo:
class: Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler
arguments: ["#pdo", "%pdo.db_options%"]
pdo:
class: PDO
arguments:
dsn: "mysql:host=%database_host%;port=%database_port%;dbname=%database_name%"
user: "%database_user%"
password: "%database_password%"
calls:
- [setAttribute, [3, 2]] # \PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION