Skip to content

Commit

Permalink
feat: создал yii2 приложение с rabbit-mq для работы с очередью
Browse files Browse the repository at this point in the history
  • Loading branch information
Artyrcha committed May 12, 2024
1 parent 7eb7d62 commit d50600a
Show file tree
Hide file tree
Showing 83 changed files with 8,061 additions and 459 deletions.
10 changes: 6 additions & 4 deletions app/.env.example
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
NGINX_CONTAINER=nginx-hw12
NGINX_CONTAINER=nginx-hw19
NGINX_PORTS=80:80

PHP_CONTAINER=php-hw12
PHP_CONTAINER=php-hw19

REDIS_CONTAINER=redis-hw12
REDIS_PORTS=6379:6379
RABBITMQ_CONTAINER=rabbitmq-19
RABBITMQ_HOST=rabbitmq
RABBITMQ_USER=user
RABBITMQ_PASS=password
33 changes: 8 additions & 25 deletions app/README.md
Original file line number Diff line number Diff line change
@@ -1,32 +1,15 @@
# Homework 12
# Homework 19

1. `cd app`
2. `cp .env.example .env`
3. `docker-compose up --build -d`
4. `docker-compose exec -it php bash`
5. `cd application.local`
4. `docker-compose exec -it consumer bash`
5. `cd /var/www/application.local`
6. `composer install`
## Команды для работы
7. `php yii consumer`
8. `Перейти в браузере по адресу` [http://application.local/](http://application.local/)

### Добавление событий
### Пример работы

`php public/index.php add --priority=1000 --event="event:1" --param1=1 --param2=1`

`php public/index.php add --priority=2000 --event="event:2" --param1=2 --param2=2`

`php public/index.php add --priority=3000 --event="event:3" --param1=1 --param2=2`

### Поиск по параметрам

`php public/index.php get --param1=1 --param2=2`

`php public/index.php get --param1=2`

### Вывести все

`php public/index.php all`

### Очистить базу

`php public/index.php clear`
![](view.png)
![](console.png)
Binary file added app/console.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
52 changes: 36 additions & 16 deletions app/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,34 +11,54 @@ services:
volumes:
- ./nginx/hosts:/etc/nginx/conf.d
- ./www:/var/www
- phpsocket:/var/run
networks:
- hw12-network
- hw19-network

php:
producer:
build:
context: ./fpm
dockerfile: Dockerfile
container_name: ${PHP_CONTAINER}
container_name: producer
volumes:
- ./www:/var/www
working_dir: /var/www
- ./fpm/zz-docker.conf:/usr/local/etc/php-fpm.d/zz-docker.conf
- phpsocket:/var/run
working_dir: /var/www/application.local
env_file:
- .env
networks:
- hw12-network
- hw19-network

redis:
image: redis
container_name: ${REDIS_CONTAINER}
ports:
- ${REDIS_PORTS}
consumer:
build:
context: ./fpm
dockerfile: Dockerfile
container_name: consumer
volumes:
- redis_data:/data
- ./www:/var/www
working_dir: /var/www/application.local
env_file:
- .env
networks:
- hw12-network
- hw19-network

networks:
hw12-network:
driver: bridge
rabbitmq:
image: rabbitmq:3.13-management
container_name: ${RABBITMQ_CONTAINER}
hostname: ${RABBITMQ_HOST}
ports:
- 15672:15672
- 5672:5672
environment:
RABBITMQ_DEFAULT_USER: ${RABBITMQ_USER}
RABBITMQ_DEFAULT_PASS: ${RABBITMQ_PASS}
networks:
- hw19-network

volumes:
phpsocket:
redis_data:

networks:
hw19-network:
driver: bridge
3 changes: 1 addition & 2 deletions app/fpm/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,7 @@ RUN apt-get update && apt-get install -y \
&& pecl install memcached \
&& docker-php-ext-enable memcached \
&& docker-php-ext-configure pgsql -with-pgsql=/usr/local/pgsql \
&& docker-php-ext-install -j$(nproc) iconv mbstring mysqli pdo_mysql zip gd pdo_pgsql pgsql \
&& docker-php-ext-install -j$(nproc) iconv mbstring mysqli pdo_mysql zip gd pdo_pgsql pgsql sockets \
&& curl -sS https://getcomposer.org/installer | php -- --install-dir=/usr/local/bin --filename=composer \
&& pecl install redis && docker-php-ext-enable redis

CMD ["php-fpm"]
11 changes: 11 additions & 0 deletions app/fpm/zz-docker.conf
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[global]
daemonize=no

[www]
user = www-data
group = www-data
listen = /var/run/php-fpm.sock

listen.owner = www-data
listen.group = www-data
listen.mode = 0666
4 changes: 2 additions & 2 deletions app/nginx/hosts/application.local.conf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
server {
listen 80;
server_name application.local;
root /var/www/application.local;
root /var/www/application.local/web;
index index.php index.html;

location ~* .(jpg|jpeg|gif|css|png|js|ico|html)$ {
Expand All @@ -16,7 +16,7 @@ server {
location ~* .php$ {
try_files $uri = 404;
fastcgi_split_path_info ^(.+.php)(/.+)$;
fastcgi_pass php:9000;
fastcgi_pass unix:/var/run/php-fpm.sock;
fastcgi_index index.php;
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
Expand Down
Binary file added app/view.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
3 changes: 3 additions & 0 deletions app/www/application.local/.bowerrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"directory" : "vendor/bower-asset"
}
33 changes: 31 additions & 2 deletions app/www/application.local/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,33 @@
.idea/
# phpstorm project files
.idea

# netbeans project files
nbproject

# zend studio for eclipse project files
.buildpath
.project
.settings

# windows thumbnail cache
Thumbs.db

# composer vendor dir
/vendor
/vendor

# composer itself is not needed
composer.phar

# Mac DS_Store Files
.DS_Store

# phpunit itself is not needed
phpunit.phar
# local phpunit config
/phpunit.xml

tests/_output/*
tests/_support/_generated

#vagrant folder
/.vagrant
31 changes: 31 additions & 0 deletions app/www/application.local/assets/AppAsset.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<?php

Check failure on line 1 in app/www/application.local/assets/AppAsset.php

View workflow job for this annotation

GitHub Actions / phpcs

Header blocks must be separated by a single blank line
/**
* @link https://www.yiiframework.com/
* @copyright Copyright (c) 2008 Yii Software LLC
* @license https://www.yiiframework.com/license/
*/

namespace app\assets;

use yii\web\AssetBundle;

/**
* Main application asset bundle.
*
* @author Qiang Xue <[email protected]>
* @since 2.0
*/
class AppAsset extends AssetBundle
{
public $basePath = '@webroot';
public $baseUrl = '@web';
public $css = [
'css/site.css',
];
public $js = [
];
public $depends = [
'yii\web\YiiAsset',
'yii\bootstrap5\BootstrapAsset'
];
}
20 changes: 20 additions & 0 deletions app/www/application.local/commands/ConsumerController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace app\commands;

use app\models\RabbitMq;
use app\models\RabbitMqConsumer;
use Exception;
use yii\console\Controller;

class ConsumerController extends Controller
{
/**
* @throws Exception
*/
public function actionIndex(): void
{
$rabbit = new RabbitMq('bank_statement');
(new RabbitMqConsumer($rabbit))();
}
}
89 changes: 74 additions & 15 deletions app/www/application.local/composer.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,76 @@
{
"name": "artyr/application.local",
"autoload": {
"psr-4": {
"AYamaliev\\hw12\\": "src/"
}
},
"authors": [
{
"name": "Artyrcha",
"email": "[email protected]"
}
],
"require": {
"ext-redis": "*"
}
"name": "yiisoft/yii2-app-basic",
"description": "Yii 2 Basic Project Template",
"keywords": ["yii2", "framework", "basic", "project template"],
"homepage": "https://www.yiiframework.com/",
"type": "project",
"license": "BSD-3-Clause",
"support": {
"issues": "https://github.com/yiisoft/yii2/issues?state=open",
"forum": "https://www.yiiframework.com/forum/",
"wiki": "https://www.yiiframework.com/wiki/",
"irc": "ircs://irc.libera.chat:6697/yii",
"source": "https://github.com/yiisoft/yii2"
},
"minimum-stability": "stable",
"require": {
"php": ">=8.0",
"yiisoft/yii2": "~2.0.45",
"yiisoft/yii2-bootstrap5": "~2.0.2",
"yiisoft/yii2-symfonymailer": "~2.0.3",
"php-amqplib/php-amqplib": "^3.6"
},
"require-dev": {
"yiisoft/yii2-debug": "~2.1.0",
"yiisoft/yii2-gii": "~2.2.0",
"yiisoft/yii2-faker": "~2.0.0",
"phpunit/phpunit": "~9.5.0",
"codeception/codeception": "^5.0.0 || ^4.0",
"codeception/lib-innerbrowser": "^4.0 || ^3.0 || ^1.1",
"codeception/module-asserts": "^3.0 || ^1.1",
"codeception/module-yii2": "^1.1",
"codeception/module-filesystem": "^3.0 || ^2.0 || ^1.1",
"codeception/verify": "^3.0 || ^2.2",
"symfony/browser-kit": "^6.0 || >=2.7 <=4.2.4"
},
"config": {
"allow-plugins": {
"yiisoft/yii2-composer" : true
},
"process-timeout": 1800,
"fxp-asset": {
"enabled": false
}
},
"scripts": {
"post-install-cmd": [
"yii\\composer\\Installer::postInstall"
],
"post-create-project-cmd": [
"yii\\composer\\Installer::postCreateProject",
"yii\\composer\\Installer::postInstall"
]
},
"extra": {
"yii\\composer\\Installer::postCreateProject": {
"setPermission": [
{
"runtime": "0777",
"web/assets": "0777",
"yii": "0755"
}
]
},
"yii\\composer\\Installer::postInstall": {
"generateCookieValidationKey": [
"config/web.php"
]
}
},
"repositories": [
{
"type": "composer",
"url": "https://asset-packagist.org"
}
]
}
Loading

0 comments on commit d50600a

Please sign in to comment.