diff --git a/Dockerfile.elasticsearch b/Dockerfile.elasticsearch new file mode 100644 index 0000000..0fdfaf8 --- /dev/null +++ b/Dockerfile.elasticsearch @@ -0,0 +1,3 @@ +FROM elasticsearch:2

 + +RUN /usr/share/elasticsearch/bin/plugin install mobz/elasticsearch-head diff --git a/docker-compose.yml b/docker-compose.yml index 1832021..3d6ceb7 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,6 +5,7 @@ services: depends_on: - mysql - rabbitmq + - elasticsearch volumes: - ./docker/shared/:/shared - ./:/mqs @@ -44,6 +45,11 @@ services: - RABBITMQ_DEFAULT_PASS=guest - RABBITMQ_DEFAULT_VHOST=mqs + elasticsearch:
 + build: { context: ., dockerfile: Dockerfile.elasticsearch }
 + ports:
 + - "9201:9200" + volumes: mysql-data: driver: local diff --git a/symfony/app/AppKernel.php b/symfony/app/AppKernel.php index 3ff5b50..5df2e8b 100644 --- a/symfony/app/AppKernel.php +++ b/symfony/app/AppKernel.php @@ -15,7 +15,9 @@ public function registerBundles() new Doctrine\Bundle\DoctrineBundle\DoctrineBundle(), new Sensio\Bundle\FrameworkExtraBundle\SensioFrameworkExtraBundle(), new AppBundle\AppBundle(), - new Enqueue\Bundle\EnqueueBundle() + new Enqueue\Bundle\EnqueueBundle(), + new Enqueue\ElasticaBundle\EnqueueElasticaBundle(), + new FOS\ElasticaBundle\FOSElasticaBundle(), ]; if (in_array($this->getEnvironment(), ['dev', 'test'], true)) { diff --git a/symfony/app/config/config.yml b/symfony/app/config/config.yml index 4373638..6524693 100644 --- a/symfony/app/config/config.yml +++ b/symfony/app/config/config.yml @@ -76,6 +76,22 @@ enqueue: router_queue: 'router' default_processor_queue: 'default' +fos_elastica: + clients: + default: { host: %elasticsearch_host%, port: %elasticsearch_port% } + indexes: + app: + index_name: app_%kernel.environment% + types: + blog: + mappings: + text: ~ + persistence: + driver: orm + model: AppBundle\Entity\Blog + provider: ~ + listener: ~ + finder: ~ services: app.async.say_hello_processor: class: 'AppBundle\Async\SayHelloProcessor' diff --git a/symfony/composer.json b/symfony/composer.json index 77e5a59..b80aa84 100644 --- a/symfony/composer.json +++ b/symfony/composer.json @@ -2,7 +2,6 @@ "name": "enqueue/message-queue-sandbox", "license": "MIT", "type": "project", - "minimum-stability": "dev", "autoload": { "psr-4": { "": "src/" }, "classmap": [ "app/AppKernel.php", "app/AppCache.php" ] @@ -19,13 +18,16 @@ "sensio/distribution-bundle": "^5.0", "sensio/framework-extra-bundle": "^3.0.2", "incenteev/composer-parameter-handler": "^2.0", - "enqueue/psr-queue": "*", - "enqueue/enqueue": "*", - "enqueue/stomp": "*", - "enqueue/amqp-ext": "*", - "enqueue/enqueue-bundle": "*", - "enqueue/job-queue": "*", - "enqueue/test": "*" + "enqueue/psr-queue": "dev-master", + "enqueue/enqueue": "dev-master", + "enqueue/stomp": "dev-master", + "enqueue/amqp-ext": "dev-master", + "enqueue/enqueue-bundle": "dev-master", + "enqueue/job-queue": "dev-master", + "enqueue/test": "dev-master", + "friendsofsymfony/elastica-bundle": "^3", + "enqueue/elastica-bundle": "dev-master", + "fzaninotto/faker": "^1.6" }, "require-dev": { "sensio/generator-bundle": "^3.0", diff --git a/symfony/src/AppBundle/Command/GenerateBlogsCommand.php b/symfony/src/AppBundle/Command/GenerateBlogsCommand.php new file mode 100644 index 0000000..0a59cdc --- /dev/null +++ b/symfony/src/AppBundle/Command/GenerateBlogsCommand.php @@ -0,0 +1,51 @@ +setName('app:generate-blogs') + ->addOption('number', null, InputOption::VALUE_REQUIRED) + ; + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $faker = \Faker\Factory::create(); + /** @var EntityManagerInterface $em */ + $em = $this->container->get('doctrine.orm.entity_manager'); + + for ($i = 1; $i <= $input->getOption('number'); $i++) { + $blog = new Blog(); + $blog->setText($faker->paragraphs(3, true)); + + $em->persist($blog); + + if (0 == ($i % 100)) { + $em->flush(); + $em->clear(); + + $output->writeln('Saved 100'); + } + + } + + $em->flush(); + $em->clear(); + + $output->writeln('Saved the rest'); + } +} diff --git a/symfony/src/AppBundle/Entity/Blog.php b/symfony/src/AppBundle/Entity/Blog.php new file mode 100644 index 0000000..c7072ba --- /dev/null +++ b/symfony/src/AppBundle/Entity/Blog.php @@ -0,0 +1,59 @@ +text; + } + + /** + * @return int + */ + public function getId() + { + return $this->id; + } + + /** + * @param int $id + */ + public function setId($id) + { + $this->id = $id; + } + + /** + * @param string $text + */ + public function setText($text) + { + $this->text = $text; + } +} \ No newline at end of file